phpnewone Posted November 12, 2010 Share Posted November 12, 2010 I'm not sure what I'm doing wrong. I have a date in a table which is formatted as: 2010-08-13 00:00:00. I am trying to change the date through PHP to display as 08-13-2010. The date is being formatted as 12-31-1969. Here's my code. if($registrant->StatusDate != '0000-00-00 00:00:00') { $formattedDate = date('m-d-Y', $registrant->StatusDate); $statusDate = ' as of ' . $formattedDate; } Can anyone advise me what I am doing wrong? Thanks! Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted November 12, 2010 Share Posted November 12, 2010 second parameter of date() function should be a timestamp $formattedDate = date('m-d-Y', strtotime($registrant->StatusDate)); Quote Link to comment Share on other sites More sharing options...
phpnewone Posted November 12, 2010 Author Share Posted November 12, 2010 That worked. Thanks! Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 12, 2010 Share Posted November 12, 2010 Why wouldn't you just format it in the query with the MySQL DATE_FORMAT() function? It's much more efficient that way. SELECT DATE_FORMAT(`date_time_field`, '%m-%d-%Y') AS StatusDate 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.