Today's use of the Timestampdiff () function in the project requires the processing of a single piece that scans the scan time to a current time greater than 24 hours. The following values summarize the usage of the Timestampdiff and Timestampadd functions.
These two functions, Timestampdiff and timestampadd, are often used in MySQL applications.
One, 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 that the interval is milliseconds
- SECOND. Seconds
- MINUTE. Minutes
- HOUR. Hours
- Day. Days
- WEEK. Week
- MONTH. Month
- QUARTER. Quarter
- Year. Years
Use the following:
- mysql> Select timestampdiff (Day,' 2012-08-24 ',' 2012-08-30 ' );
- +----------------------------------------------+
- | Timestampdiff (Day,' 2012-08-24 ',' 2012-08-30 ') |
- +----------------------------------------------+
- | 6 |
- +----------------------------------------------+
- 1 row in Set (0.00 sec)
- mysql> Select timestampdiff (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 |
- +-------------------------------------------------------------------+
- 1 row in Set (0.01 sec)
Two, Timestampadd syntax: Timestampadd (interval,int_expr,datetime_expr) Description: Adds an integer 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> Select timestampadd (MINUTE, 8820,' 2012-08-24 09:00:00 ');
- +-------------------------------------------------+
- | Timestampadd (MINUTE, 8820,' 2012-08-24 09:00:00 ') |
- +-------------------------------------------------+
- | 2012-08-30 12:00:00 |
- +-------------------------------------------------+
- 1 row in Set (0.00 sec)
The use of Timestampdiff and Timestampadd functions in MySQL