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

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

Genesis Framework for WordPress

Advertise Here


  • Scott: Just moved changed the site URL as WP's installed in a subfolder. Cookie clearance worked for me. Thanks!
  • Stephen Lareau: Hi great blog thanks. Just thought I would add that it helps to put target = like this:1-800-555-1212 and
  • Cord Blomquist: Jennifer, you may want to check out tp2wp.com, a new service my company just launched that converts TypePad and Movable Type export files into WordPre

About


Advertisements