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
When we check the source code of many websites, w...
Anchor tag usage: Linking to a specific location i...
Table of contents Observer Pattern Vue pass value...
clear:both is used to清除浮動This is the impression I...
The World Wide Web Consortium (W3C) has released a...
This article example shares the specific code of ...
Canvas has always been an indispensable tag eleme...
MySQL 8.0.12 download and installation tutorial f...
<br /> CSS syntax for table borders The spec...
The specific code for implementing skinning with ...
After studying React for a while, I want to put i...
1. Run fonts, open the font folder, and find the ...
Download the zip installation package: Download a...
This article shares the specific code of js+canva...
Why mention textarea specifically? Because the tex...