wemustdesign Posted October 22, 2010 Share Posted October 22, 2010 Hi, I have the date stored in my datrabase like this: 2010-04-03 I am then outputting the date like this: Sat 13 Nov This is done using this code: list($year,$month,$day) = explode('-',$Coursedate); $time_stamp = mktime(0,0,0,$month,$day); $Coursedate2 = date("D d M",$time_stamp); The problem I have come across is when listing a date for next year. The database has a value of 2011-01-29 which is a Saturday but it is outputting it as a Friday: Fri 29 Jan The 29th of January 2010 is a Friday but 2010 is a Saturday. Any idea what is wrong with the code? Quote Link to comment Share on other sites More sharing options...
litebearer Posted October 22, 2010 Share Posted October 22, 2010 quoted from - http://forums.devarticles.com/mysql-development-50/mysql-datetime-w-php-7624.html There's a few different solutions... first of all, you could format the actual return result using the SQL statement... SELECT DATE_FORMAT(date_field, '%W, %y.%m.%e @ %h:%i %p') FROM table Refer to this: http://www.mysql.com/doc/en/Date_an..._functions.html Or you could try the PHP date functions: http://ca3.php.net/manual/en/function.date.php -------------------------------------------------------------------------------- Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted October 22, 2010 Share Posted October 22, 2010 Ummm... you forgot the year: $time_stamp = mktime(0,0,0,$month,$day,$year); Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted October 22, 2010 Share Posted October 22, 2010 Just use strtotime and date <?php $Coursedate2 = date("D d M",strtotime($Coursedate)); ?> Ken Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted October 22, 2010 Share Posted October 22, 2010 Just use strtotime and date <?php $Coursedate2 = date("D d M",strtotime($Coursedate)); ?> Ken +1 Haha. I always propose strtotime(), but this time I was so focused on the problem that I didn't... Oh well. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.