Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

MySQL calculates the number of days, months and years of the difference between the two dates

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

The date function TIMESTAMPDIFF provided by MySQL calculates the difference between two dates in seconds, minutes, hours, days, weeks, quarters, months, years, and the current date increases or decreases by one day, one week, and so on.

SELECT TIMESTAMPDIFF (type, start time, end time)

Number of seconds of difference:

SELECT TIMESTAMPDIFF (SECOND,'1993-03-23 00 NOW (),'% Y-%m-%d% HV% iRO% S'))

Number of minutes of difference:

SELECT TIMESTAMPDIFF (MINUTE,'1993-03-23 00 NOW (),'% Y-%m-%d% HV% iRO% S'))

Hours of difference:

SELECT TIMESTAMPDIFF (HOUR,'1993-03-23 00:00:00 00-00-00-12-12-00-00-00-12-00-00-00-12-00-00-12-00-00-12-00-00-12-00, NOW (),'% Y-%m-%d% HV% iRO% S')

Number of days of difference:

SELECT TIMESTAMPDIFF (DAY,'1993-03-23 00 NOW (),'% Y-%m-%d% HV% iRO% S'))

Number of weeks of difference:

SELECT TIMESTAMPDIFF (WEEK,'1993-03-23 00 NOW (),'% Y-%m-%d% HV% iRO% S'))

Number of quarters with a difference:

SELECT TIMESTAMPDIFF (QUARTER,'1993-03-23 00 NOW (),'% Y-%m-%d% HV% iRO% S'))

Number of months of difference:

SELECT TIMESTAMPDIFF (MONTH,'1993-03-23 00 NOW (),'% Y-%m-%d% HV% iRO% S'))

Number of years of difference:

SELECT TIMESTAMPDIFF (YEAR,'1993-03-23 00 NOW (),'% Y-%m-%d% HV% iRO% S'))

Get the current date:

SELECT NOW () SELECT CURDATE ()

Add one day to the current date:

SELECT DATE_SUB (CURDATE (), INTERVAL-1 DAY)

The current date is reduced by one day:

SELECT DATE_SUB (CURDATE (), INTERVAL 1 DAY)

The current date is increased by one week:

SELECT DATE_SUB (CURDATE (), INTERVAL-1 WEEK) SELECT DATE_SUB (NOW (), INTERVAL-1 MONTH)

The current date is increased by January:

SELECT DATE_SUB (CURDATE (), INTERVAL-1 MONTH) FRAC_SECOND millisecond SECOND second MINUTE minute HOUR hour DAY day WEEK week MONTH month QUARTER quarter YEAR year

Summary

The above is the MySQL introduced by the editor to calculate the number of days, months and years of the difference between the two dates. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to the website!

If you think this article is helpful to you, you are welcome to reprint it, please indicate the source, thank you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report