Jump to content

[SOLVED] strange DATETIME field problem


houseofdreams

Recommended Posts

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'])); ?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/51237-solved-strange-datetime-field-problem/
Share on other sites

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

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 

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.