Jump to content

[SOLVED] date formating


hellonoko

Recommended Posts

My below code to format the time in a DB echo's two different times. The first date being correct. the date is stored in the db as a DATETIME value.

 

$query = "SELECT duedate FROM ideas WHERE id = '18'";
$result = mysql_query($query);
$rows = mysql_fetch_array($result);

$duedate = $rows[0];
echo $duedate;
echo "<br>";
$duedate = date('F j Y H:i:s',$duedate);
echo "<br>";
echo $duedate;
exit();

 

Output:

2007-12-28 14:59:59

December 31 1969 16:33:27

 

Any reason why they are different?

Am I using date() incorrectly?

 

Thanks for your time,

ian

Link to comment
https://forums.phpfreaks.com/topic/83450-solved-date-formating/
Share on other sites

The date is being returned from sql to php as "2007-12-28 14:59:59" which to the date function means nothing.  The date function takes an integer as its second paramenter, desired to be a unix time stamp.  You can either pull the date from MySQL as a timestamp, or you can just do this:

 

$query = "SELECT duedate FROM ideas WHERE id = '18'";
$result = mysql_query($query);
$rows = mysql_fetch_array($result);

$duedate = $rows[0];
echo $duedate;
echo "<br>";
$duedate = date('F j Y H:i:s',strtotime($duedate));
echo "<br>";
echo $duedate;

Link to comment
https://forums.phpfreaks.com/topic/83450-solved-date-formating/#findComment-424548
Share on other sites

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.