Sunday, February 15, 2009

Right date format to store in mysql - YYYY-MM-DD HH:MM:SS

When using the php date function you can format the date in lot of ways.
But when you store date and time in mysql it is really convenient to store date in the mysql friendly format YYYY-MM-DD HH:MM:SS
If you use the above format you can easily use mysql date functions to manipulate and do calculation on stored dates without using php functions.

Example functions
DATEDIFF() - Subtract two dates
ADDDATE() - Add dates
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html

No comments:

Post a Comment