content_image/757753.jpg
• TIMESTAMPADD( unit , interval , datetime_expr ) 

Adds the integer expression interval  to the date or datetime expression datetime_expr . The unit for interval  is given by the unit  argument, which should be one of the following values: MICROSECOND  (microseconds), SECOND , MINUTE , HOUR , DAY , WEEK , MONTH , QUARTER , or YEAR . 

The unit  value may be specified using one of keywords as shown, or with a prefix of SQL_TSI_ . For example, DAY  and SQL_TSI_DAY  both are legal. 

mysql> SELECT TIMESTAMPADD(MINUTE,1,’2003-01-02’); -> ’2003-01-02 00:01:00’ mysql> SELECT TIMESTAMPADD(WEEK,1,’2003-01-02’); -> ’2003-01-09’ 

• TIMESTAMPDIFF( unit , datetime_expr1 , datetime_expr2 ) 

Returns datetime_expr2 − datetime_expr1 , where datetime_expr1  and datetime_expr2 are date or datetime expressions. One expression may be a date and the other a datetime; a date value is treated as a datetime having the time part ’00:00:00’  where necessary. The unit for the result (an integer) is given by the unit  argument. The legal values for unit  are the same as those listed in the description of the TIMESTAMPADD()  function. 

mysql> SELECT TIMESTAMPDIFF(MONTH,’2003-02-01’,’2003-05-01’); -> 3 mysql> SELECT TIMESTAMPDIFF(YEAR,’2002-05-01’,’2001-01-01’); -> -1 mysql> SELECT TIMESTAMPDIFF(MINUTE,’2003-02-01’,’2003-05-01 12:05:55’); -> 128885 

<img src='content_image/757753.jpg'>

• TIME_FORMAT( time , format ) 

## Note 

The order of the date or datetime arguments for this function is the opposite of that used with the TIMESTAMP()  function when invoked with 2 arguments. 

This is used like the DATE_FORMAT()  function, but the format  string may contain format specifiers only for hours, minutes, seconds, and microseconds. Other specifiers produce a NULL  value or 0 . 

If the time  value contains an hour part that is greater than 23 , the %H  and %k  hour format specifiers produce a value larger than the usual range of 0..23 . The other hour format specifiers produce the hour value modulo 12. 

mysql> SELECT TIME_FORMAT(’100:00:00’, ’%H %k %h %I %l’); -> ’100 100 04 04 4’ 

• TIME_TO_SEC( time ) 

Returns the time  argument, converted to seconds. 

mysql> SELECT TIME_TO_SEC(’22:23:00’); -> 80580 mysql> SELECT TIME_TO_SEC(’00:39:38’); -> 2378 

• TO_DAYS( date ) 

Given a date date , returns a day number (the number of days since year 0). 

mysql> SELECT TO_DAYS(950501); -> 728779 

