rkstevens Posted May 6, 2008 Share Posted May 6, 2008 I have the following code: $formatdate = "l F n, Y g:ia"; echo (date($formatdate,$concertinfo[EventDate])); $concertinfo[EventDate] is a timestamp stored in a database with the value of: 2008-08-20 20:00:00 but when I display it using the above date function, I get: Wednesday December 12, 1969 7:33pm What do I have wrong? Link to comment https://forums.phpfreaks.com/topic/104398-solved-invalid-datetime-being-displayed/ Share on other sites More sharing options...
ILYAS415 Posted May 6, 2008 Share Posted May 6, 2008 [code]try changing [code]$formatdate = "l F n, Y g:ia"; to [/code]$formatdate = "Y F n, l g:ia";[/code] Link to comment https://forums.phpfreaks.com/topic/104398-solved-invalid-datetime-being-displayed/#findComment-534440 Share on other sites More sharing options...
rkstevens Posted May 6, 2008 Author Share Posted May 6, 2008 [code]try changing [code]$formatdate = "l F n, Y g:ia"; to [/code]$formatdate = "Y F n, l g:ia";[/code] Displays: 1969 December 12, Wednesday 7:33pm Link to comment https://forums.phpfreaks.com/topic/104398-solved-invalid-datetime-being-displayed/#findComment-534443 Share on other sites More sharing options...
rkstevens Posted May 6, 2008 Author Share Posted May 6, 2008 I know I have one mistake, that the lower-case 'n' should be a lower-case 'j', but it still displays wrong: $formatdate = "l F j, Y g:ia"; Link to comment https://forums.phpfreaks.com/topic/104398-solved-invalid-datetime-being-displayed/#findComment-534448 Share on other sites More sharing options...
PFMaBiSmAd Posted May 6, 2008 Share Posted May 6, 2008 Ummm. The php date() function takes a Unix Timestamp as the second parameter. You are giving it a yyyy-mm-dd hh:mm:ss value. To format a DATETIME from your database, use the mysql DATE_FORMAT() function directly in the query - http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_date-format Link to comment https://forums.phpfreaks.com/topic/104398-solved-invalid-datetime-being-displayed/#findComment-534602 Share on other sites More sharing options...
rkstevens Posted May 6, 2008 Author Share Posted May 6, 2008 I had just thought of that, and replaced the $variable with strtotime($variable) and it worked. Thank you. Link to comment https://forums.phpfreaks.com/topic/104398-solved-invalid-datetime-being-displayed/#findComment-534617 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.