houseofdreams Posted May 13, 2007 Share Posted May 13, 2007 Hello, I have multiple php pages, on the first page, i pull data from the mysql database, where one field is set as a DATETIME field. The code to display it on the page is : <?php echo date("l, j F Y", $row_rsDETAILS['cDATETIME']); ?> the actual data in the database : 2007-05-13 21:04:00 But when i open the php page, i get the following date : Thursday, 1 January 1970 Does anyone have an idea? PS : i allready tried the following strtotime part : <?php echo date("l, j F Y", strtotime($row_rsDETAILS['cDATETIME'])); ?> Quote Link to comment https://forums.phpfreaks.com/topic/51237-solved-strange-datetime-field-problem/ Share on other sites More sharing options...
toplay Posted May 13, 2007 Share Posted May 13, 2007 The first code example will not work because date() PHP function requires a UNIX timestamp passed and not a MySQL timestamp. The second code example may or may not work, I don't remember. The strtotime() function only can convert certain date formats. Look here: http://www.gnu.org/software/tar/manual/html_node/tar_110.html#SEC110 It's best to format the date you want in your SQL select query itself using the MySQL DATE_FORMAT() function. See: http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_date-format Quote Link to comment https://forums.phpfreaks.com/topic/51237-solved-strange-datetime-field-problem/#findComment-252388 Share on other sites More sharing options...
Barand Posted May 13, 2007 Share Posted May 13, 2007 The strtotime version should do it. Are you sure your query is OK and $row_rsDETAILS['cDATETIME'] contains what you expect. <?php $d = '2007-05-13 21:04:00'; echo date('l, j F Y', strtotime($d)); //--> Sunday, 13 May 2007 ?> Quote Link to comment https://forums.phpfreaks.com/topic/51237-solved-strange-datetime-field-problem/#findComment-252394 Share on other sites More sharing options...
Dragen Posted May 13, 2007 Share Posted May 13, 2007 edit Quote Link to comment https://forums.phpfreaks.com/topic/51237-solved-strange-datetime-field-problem/#findComment-252398 Share on other sites More sharing options...
houseofdreams Posted May 13, 2007 Author Share Posted May 13, 2007 thanx for the reply guys ! One little question : how can i convert a date, let's say the today's date into a unix timestamp, before inserting it in the mysql database? sorry if this is "noob" Quote Link to comment https://forums.phpfreaks.com/topic/51237-solved-strange-datetime-field-problem/#findComment-252400 Share on other sites More sharing options...
houseofdreams Posted May 13, 2007 Author Share Posted May 13, 2007 Found it, is was so simple, i completely overlooked the time() function... thanx again for the quick reply's ! Quote Link to comment https://forums.phpfreaks.com/topic/51237-solved-strange-datetime-field-problem/#findComment-252414 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.