1. SyntaxTIMESTAMPDIFF(unit,begin,end); Returns the time difference according to the unit. The data structures of the passed begin and end do not need to be the same. One can be Date and the other can be DateTime. 2. UnitSupported units include:
3. ExampleThe following example is the most basic usage of TIMESTAMPDIFF.
SELECT TIMESTAMPDIFF(MONTH, '2017-01-01', '2017-02-01') as result; +--------+ | result | +--------+ | 1 | +--------+ 1 row in set (0.00 sec)
SELECT TIMESTAMPDIFF(DAY, '2017-01-01', '2017-02-01') as result; +--------+ | result | +--------+ | 31 | +--------+ 1 row in set (0.00 sec)
SELECT TIMESTAMPDIFF(MINUTE, '2017-01-01 08:00:00', '2017-01-01 08:55:00') result; +--------+ | result | +--------+ | 55 | +--------+ 1 row in set (0.00 sec)
SELECT TIMESTAMPDIFF(MINUTE, '2017-01-01 08:00:00', '2017-01-01 08:55:33') result; +--------+ | result | +--------+ | 55 | +--------+ 1 row in set (0.00 sec)
SELECT TIMESTAMPDIFF(SECOND, '2017-01-01 08:00:00', '2017-01-01 08:55:33') result; 55 * 60 + 33 = 3333 +--------+ | result | +--------+ | 3333 | +--------+ 1 row in set (0.00 sec)
This is the end of this article about the detailed explanation of TIMESTAMPDIFF case in MySQL. For more relevant content about TIMESTAMPDIFF in MySQL, please search the previous articles of 123WORDPRESS.COM or continue to browse the related articles below. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: HTML head tag meta to achieve refresh redirection
>>: Nginx cache configuration example
The process of completely uninstalling the MySQL ...
1. HTML tags with attributes XML/HTML CodeCopy co...
Development Trends: html (Hypertext Markup Languag...
Table of contents Preface 1. Iceraven Browser (Fi...
Before talking about the structural markup of web...
Preface This article mainly shares with you an ex...
Rendering principle In the form element, there is...
Table of contents Short Polling Long-Polling WebS...
Some time ago, I submitted a product version to t...
MySQL version 5.0 began to support stored procedu...
Table of contents 1. Original value and reference...
Here are 10 tips on how to design better-usable w...
Recently, in order to realize the course design, ...
1. Business scenario introduction Suppose there i...
Effect Need environment vue elementUI Drag and dr...