Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.