scriptygoddess

13 Sep, 2002

Getting Readable Dates from Mysql…

Posted by: dave In: Lessons learned

Well.. this took me a little while, and I'm somewhat embarrased to admit it…

I was writing a script to pull some data from several tables, and the date field looked something like this:
1031849565

Its a Unix Timestamp (representing the number of seconds from Jan, 1 1970 up to sometime in 2037), and luckily MySQL gives you a good way to convert them into readable dates. When you make a SQL query, just add this around the timestamp field:

FROM_UNIXTIME(yourtable.yourfield, '%d, %m, %Y')

So a sample query would look like:

SELECT FROM_UNIXTIME(yourtable.yourfield, '%d, %m, %Y') WHERE yourtable.index > 0;

The %d, %m etc. represent date & time format variables… a complete list can be found in the MySQL Documentation in section 6.3.4

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

1 Response to "Getting Readable Dates from Mysql…"

1 | erica

September 13th, 2002 at 9:46 am

Avatar

I must admit, the goddessDave bit made me stop for a second.

Featured Sponsors

About


Advertisements