Chris Nizzardini, Salt Lake City Utah, Web Developer Specializing in LAMP+Ajax Since 2006

My Blog

Here is my awesome blog. You can find information on programming, linux, documentation, tips for code and database optimization, my thoughts and rants, and whatever else I feel like sharing. Feel free to contribute to the blog by posting comments and asking questions.
SQL

mysql date/time functions

Better than using PHP to time format date times stored in your database for easier human readability is using MySQLs built in functions:

To turn a date time stamp into a readable time on the 12 hour clock with an AM/PM signifier
TIME_FORMAT(date_time,’%h:%I:%l %p’) as time

Returning just the date time portion of date time stamp
DATE(date_time) as date

Make a date pretty
Unlike the actual dates I go on, in MySQL you can actually make her pretty, the following code would convert 2008-01-01 into Jan 01, 2008.
DATE_FORMAT(tour.date_time,’%b %d, %Y’) as date

http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html

Related posts:

  1. MySQL Union

Leave a Reply