| A list of the more useful date and time functions is shown in Table 8.5. Because of MySQL's data warehousing heritage, it has a very extensive set of time and date functions. The list here is far from complete. Table 8.5. Date and Time Functions
Let's look at an example using adddate() . We will start from the 1st of January 1999 and add 1 year and 6 months to it: select adddate("1999-01-01", INTERVAL "1-6" YEAR_MONTH); We get the following result: +--------------------------------------------------+ adddate("1999-01-01", INTERVAL "1-6" YEAR_MONTH) +--------------------------------------------------+ 2000-07-01 +--------------------------------------------------+ 1 row in set (0.41 sec) For many applications in which you are formatting output with an external program, this may not be the most useful way to receive the date. Unix timestamps are not humanly readable, but they are very compatible with the APIs that come with other programming languages. The same query with the unix_timestamp() function select unix_timestamp(adddate("1999-01-01", INTERVAL "1-6" YEAR_MONTH)); generates output useless to humans but directly usable by other code that is such as the date() function built into PHP: +------------------------------------------------------------------+ unix_timestamp(adddate("1999-01-01", INTERVAL "1-6" YEAR_MONTH)) +------------------------------------------------------------------+ 962373600 +------------------------------------------------------------------+ 1 row in set (0.01 sec) |