Re: [PHP] Date confusion
On Jul 28, 2005, at 9:28 AM, Linda H wrote: Hi, I must admit I am surprised at the paucity of date and time functions in PHP. I have a date stored in a MySQL database in field of datatype date. PHP doesn't seem to have a function I can use to format it for print. I tried the following but regardless of the value in the date field, it displays as 'Wednesday December 31, 1969' (I know this is the day before the UNIX epoch.). echo 'p'.date('l F j, Y',$start_date).'/p'; I tried casting the field to datetime, but it didn't pass the parser. Finally I did the following, which seems to work, but is awfully convoluted: echo 'pDate: '.date('l F j, Y',strtotime($start_date).'/p'; The other thing I'm concerned about is that strtotime takes the locale into consideration. I don't want it adjusting the date - I just want it printed out. Is there a better way to do this? SELECT DATE_FORMAT(myfield, '%W %M %e, %Y') as 'formatted_date' FROM -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Date confusion
Linda H wrote: Hi, I must admit I am surprised at the paucity of date and time functions in PHP. I have a date stored in a MySQL database in field of datatype date. PHP doesn't seem to have a function I can use to format it for print. I tried the following but regardless of the value in the date field, it displays as 'Wednesday December 31, 1969' (I know this is the day before the UNIX epoch.). echo 'p'.date('l F j, Y',$start_date).'/p'; I tried casting the field to datetime, but it didn't pass the parser. Finally I did the following, which seems to work, but is awfully convoluted: echo 'pDate: '.date('l F j, Y',strtotime($start_date).'/p'; The other thing I'm concerned about is that strtotime takes the locale into consideration. I don't want it adjusting the date - I just want it printed out. Is there a better way to do this? If you have it in MySQL, there are a bunch of native MySQL functions to format it on the select itself. See http://mysql.com/datetime Or, if you want to manipulate it using PHP's functions, get MySQL to return it to you as a UNIX timestamp. -Rasmus -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Date confusion
hi Linda I must admit I am surprised at the paucity of date and time functions in PHP. You may want to check out the PEAR Date class: http://pear.php.net/package/Date Rob -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Date Confusion
On Sunday, September 7, 2003, at 02:50 PM, Seth Willits wrote: A few things I'm trying to do: 1) Turn MM/DD/YY into an array like that returned from getdate(). I don't want to explode it or split it, I want to get an array just as if I used getdate() when the current day was MM/DD/YY. It just dawned on me that the timestamp parameter for getdate() is exactly what does this. So forget this one :) 2) Have a date string representing the first of the month and manipulate it to be the last day of the previous month. This, I'm still wondering about. This is the code I have: $month = $date['mon']; $year = $date['year']; if ($month == 1) { $lastofprevmonth = date('t', strtotime('12' . '/01/' . ($year-1) )); $lastofprevmonth = date('m/d/y', strtotime('12' . '/' . $lastofprevmonth . '/' . ($year-1))); } else { $lastofprevmonth = date('t', strtotime(($month-1) . '/01/' . $year)); $lastofprevmonth = date('m/d/y', strtotime(($month-1) . '/' . $lastofprevmonth . '/' . $year)); } This is a far cry from the simple trick in other languages where you just subtract one from the first of the current month and your date then reflects the last day of the previous month. Can that be done in PHP? Seth Willits --- President and Head Developer of Freak Software - http://www.freaksw.com QA Columnist for REALbasic Developer Magazine - http://www.rbdeveloper.com Webmaster for REALbasic Game Central - http://www.freaksw.com/rbgames When purchasing that gift for your Special Someone guys remember, girls like cute things. If it makes you want to puke, your chick will totally love it. -- Someone else out There --- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Date Confusion
Seth Willits wrote: 2) Have a date string representing the first of the month and manipulate it to be the last day of the previous month. You can use mktime() for this. To get the last day of a given month, just give the parameters for the zeroth day of the next month. For example, to get the date for the end of $month: $month = 4; $year = 2003; $endofmonth = date('m/d/y',mktime(12,0,0,$month+1,0,$year)); $endofmonth is now the last day of the April for 2003 in MM/DD/YY format. -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals www.phparch.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php