Jump to content

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 

?>

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.