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! Link to comment https://forums.phpfreaks.com/topic/218520-date-formatting/ 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)); Link to comment https://forums.phpfreaks.com/topic/218520-date-formatting/#findComment-1133615 Share on other sites More sharing options...
phpnewone Posted November 12, 2010 Author Share Posted November 12, 2010 That worked. Thanks! Link to comment https://forums.phpfreaks.com/topic/218520-date-formatting/#findComment-1133618 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 Link to comment https://forums.phpfreaks.com/topic/218520-date-formatting/#findComment-1133622 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.