HomeContact

Calculating Date, Time in SQL-mysql

Published in Server
May 16, 2023
1 min read

DATEDIFF(): Calculating the number of days between two periods

TIMEDIFF(): Calculation of time between two periods

PERIOD_DIFF(): Calculating the number of months between two periods

TIMESTAMPDIFF(): Calculation of time between two periods


🌱DATEDIFF()

SELECT DATEDIFF('2023-12-31','2023-01-02');
>> 345


🌱TIMEDIFF()

SELECT TIMEDIFF('2023-02-01 23:00:00','2023-01-30 00:00:00');
>> 71:00:00


🌱PEROID_DIFF()

SELECT PERIOD_DIFF('202302','202212');
>> 2
SELECT PERIOD_DIFF('202202','201212');
>> -10
SELECT PERIOD_DIFF('2202','1912');
>> 26


🌱TIMESTAMPDIFF()

SELECT TIMESTAMPDIFF(MONTH,'2022-02-01','2023-03-01');
>> 13
SELECT TIMESTAMPDIFF(SECOND,'2023-02-01 23:00:00','2023-02-01 23:00:05');
>> 5
SELECT TIMESTAMPDIFF(MINUTE,'2023-02-01 23:00:00','2023-02-01 23:03:00');
>> 3

Tags

#Server#mysql

Share


Previous Article
How to use Java Regular Expression

Topics

Java
Other
Server

Related Posts

How to set Linux crontab time
April 25, 2023
1 min