Page 1 of 1

Displaying a timestamp in different formats

Posted: Thu Jul 16, 2009 1:19 pm
by pftodd
Hi
As part of a news system I am constructing, each post will have a timestamp. It is entered into my database in the following format: 2009-07-02 14:13:41

To display this on a page I am using this code:

Code: Select all

<?php echo $row->timestamp; ?>
Is it possible to display this timestamp (2009-07-02 14:13:41) in different formats, such as in the format of d/m/y ?

Thanks for any help.

Re: Displaying a timestamp in different formats

Posted: Thu Jul 16, 2009 1:30 pm
by requinix
Getting this date from MySQL? Try the MySQL solution.

Re: Displaying a timestamp in different formats

Posted: Thu Jul 16, 2009 1:32 pm
by califdon
There's a lot of confusion about the various date/time storage and display formats, the differences between what PHP and MySQL call "timestamp", and even between versions of MySQL! Read the manual: http://dev.mysql.com/doc/refman/5.0/en/timestamp.html and some of the other references you'll find searching the web with search terms like mysql timestamp and php timestamp. Generally, you can use PHP's date() function to format most date/times to your preference, but there are a few traps.

Re: Displaying a timestamp in different formats

Posted: Thu Jul 16, 2009 3:44 pm
by pftodd
Thanks; got it sorted.