Jump to content

Formatting a date coming from a database table


lalnfl

Recommended Posts

I am have troubles displaying a date. I got the information from the database. Then I used the date() function.

 

This is how it looks:

 

$date = date('M j,Y' , $post_date);

 

the $post_date is from the database query

 

I defined it as $post_date = $row3['post_time'];

 

In the database I am using datetime for the post_time field

 

If you understand the mess I just said, do you know what I am doing wrong? And please show examples.

 

I did echo it, but when I did, it display Dec 31, 1969. The day should be Jul 9, 2010

Hello,

 

The datetime field stores the date and time as a string in the format "Y-m-d h:i:s A". As this is a string format, you can not format the date string without converting it back into a timestamp variable type.

 

Try the following

$post_date = strtotime($row3['post_time']);

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.