MySQL calculates the number of days, months and years of the difference between the two dates
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!