Displaying a timestamp in different formats

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pftodd
Forum Newbie
Posts: 5
Joined: Wed Jun 24, 2009 1:38 pm

Displaying a timestamp in different formats

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Displaying a timestamp in different formats

Post by requinix »

Getting this date from MySQL? Try the MySQL solution.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Displaying a timestamp in different formats

Post 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.
pftodd
Forum Newbie
Posts: 5
Joined: Wed Jun 24, 2009 1:38 pm

Re: Displaying a timestamp in different formats

Post by pftodd »

Thanks; got it sorted.
Post Reply