Forum Moderators: coopster

Message Too Old, No Replies

Converting "UNIX" time to a readable date/time

How to do?

         

chiyo

4:53 am on May 10, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I hope someone may help me here. It may be easy for a PHP expert!

We have conbbled together and hacked away at a few open source php scripts to produce a working web page that displays the latest news items from a group of RSS feeds (An aggregated feed) by recency, then deletes them after a few days. It does this by parsing rss feeds, placing the data in a simple text database, and then reading that database, sorting and deleting and adding as the page is viewed.

I can work out how to retrieve text info such as the article titile and date, URL and description and display it as an item on the page.

Now one of the fields in the database is a long string of digits which documentation says in unix time and the internal script uses this to sort items by recency.

What i would like to do is to convert that "UNIX time" field into a readable date such as "May 9th 2003 3:20pm" so as well as the headline, link and description i can also say "Indexed May 9th 2003 3:20pm"

Can anybody direct me to a good specific resource, such as the page in a php manual which described how to do this in common english? or if its simple maybe contribute a "snippet" here.

Thanks

eaden

5:07 am on May 10, 2003 (gmt 0)

10+ Year Member



the php "date" function does that for you ( [php.net...] )

e.g. echo date("d/m/Y",123124124);

which would produce something like

12/05/2003

( where 123124... is your unix timestamp )

jatar_k

5:11 am on May 10, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



no prob chiyo,

if you have a unix timestamp already then making it into a readable date is very simple, only one function.

strftime [php.net]

May 9th 2003 3:20pm can be constructed like so

you assign the unix timestamp to a var
$indexed = var_from_db;
$realtime = strftime("%B %d %Y %r",$indexed);

think the pattern is right but the link will show you all of the possibilities.

chiyo

9:49 am on May 10, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



thanks a lot guys. sure saved me a lot of time