Timestampdiff
Grammar:
Timestampdiff (INTERVAL,DATETIME_EXPR1,DATETIME_EXPR2).
Description
Returns an integer difference between a date or datetime expression Datetime_expr1 and datetime_expr2the. The unit of the result is given by the interval parameter. The parameter must be one of the following values:
- Frac_second---(indicates the interval is milliseconds)
- SECOND---(sec)
- MINUTE---(minutes)
- HOUR---(hours)
- Day---(days)
- WEEK---(week)
- Month---(months)
- QUARTER---(quarterly)
- Year---(years)
Use the following:
Mysql> SelectTimestampdiff ( Day,'2012-08-24','2012-08-30'); +----------------------------------------------+ |Timestampdiff ( Day,'2012-08-24','2012-08-30')| +----------------------------------------------+ | 6 | +----------------------------------------------+ 1Rowinch Set(0.00Sec
Mysql> SelectTimestampdiff (MINUTE,'2012-08-24 09:00:00','2012-08-30 12:00:00'); +-------------------------------------------------------------------+ |Timestampdiff (MINUTE,'2012-08-24 09:00:00','2012-08-30 12:00:00')| +-------------------------------------------------------------------+ | 8820 | +-------------------------------------------------------------------+ 1Rowinch Set(0.01Sec
Timestampadd
Syntax: Timestampadd (interval,int_expr,datetime_expr) Description: Adds an integral expression int_expr to a date or datetime expression datetime_expr. The interval in the formula are the same as the values listed above.
Mysql> SelectTimestampadd (MINUTE,8820,'2012-08-24 09:00:00'); +-------------------------------------------------+ |Timestampadd (MINUTE,8820,'2012-08-24 09:00:00')| +-------------------------------------------------+ | -- ,- - A:xx:xx | +-------------------------------------------------+ 1Rowinch Set(0.00Sec
From: http://blog.csdn.net/zmxiangde_88/article/details/8011661
The use of Timestampdiff and Timestampadd functions in MySQL