Sunday, March 16, 2008

Date and Time Functions in MySQL

Quite often I am having to perform date and time calculations in my applications. Earlier I was doing all these things in Ruby. But later I realized these things will be faster and better if performed by the database engine. These calculations become cumbersome as they become complex. Here is a link to MySQL's date and time functions.

2 of the most commonly used functions:
  • Add an interval to a date and get back the updated date.
     DATE_ADD(s.expires_on, INTERVAL p.expiration_buffer DAY)
  • Return date in a particular format. In this case "2008-03-17"

No comments: