The MySQL built-in date function TIMESTAMPDIFF calculates the number of seconds, minutes, hours, days, weeks, quarters, months, years between two dates, and increases or decreases the current date by one day, a week, etc. SELECT TIMESTAMPDIFF(type, start time, end time) Difference in seconds: SELECT TIMESTAMPDIFF(SECOND,'1993-03-23 00:00:00',DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%S')) Difference in minutes: SELECT TIMESTAMPDIFF(MINUTE,'1993-03-23 00:00:00',DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%S')) Difference in hours: SELECT TIMESTAMPDIFF(HOUR,'1993-03-23 00:00:00 00:00:00',DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%S')) Difference in days: SELECT TIMESTAMPDIFF(DAY,'1993-03-23 00:00:00',DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%S')) Weeks difference: SELECT TIMESTAMPDIFF(WEEK,'1993-03-23 00:00:00',DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%S')) Number of quarters difference: SELECT TIMESTAMPDIFF(QUARTER,'1993-03-23 00:00:00',DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%S')) Difference in months: SELECT TIMESTAMPDIFF(MONTH,'1993-03-23 00:00:00',DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%S')) Difference in years: SELECT TIMESTAMPDIFF(YEAR,'1993-03-23 00:00:00',DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%S')) Get the current date: SELECT NOW() SELECT CURDATE() Add one day to the current date: SELECT DATE_SUB(CURDATE(),INTERVAL -1 DAY) Subtract one day from the current date: SELECT DATE_SUB(CURDATE(),INTERVAL 1 DAY) Add one week to the current date: SELECT DATE_SUB(CURDATE(),INTERVAL -1 WEEK) SELECT DATE_SUB(NOW(),INTERVAL -1 MONTH) Add one month to the current date: SELECT DATE_SUB(CURDATE(),INTERVAL -1 MONTH) FRAC_SECOND milliseconds SECOND seconds MINUTE minutes HOUR hours DAY days WEEK weeks MONTH months QUARTER quarters YEAR years Summarize The above is the introduction of MySQL to calculate the number of days, months, and years between two dates. I hope it will be helpful to everyone. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website! You may also be interested in:
|
<<: JS implements WeChat's "shit bombing" function
>>: How to install JDK and set environment variables in Linux (this article is enough)
Preface Managing routing is an essential feature ...
Problem Description When VMware Workstation creat...
This article example shares the specific code of ...
The following information is compiled from the Int...
Table of contents 1. CDN introduction 1.1 react (...
Table of contents Overview 1. Dependency Injectio...
Table of contents 01 Introduction to InnoDB Repli...
MySQL green version setting code, and 1067 error ...
This tutorial shares the installation tutorial of...
When we check the source code of many websites, w...
MySQL 5.7 MySQL command line client using command...
Table of contents Preface 1. Install Docker 2. In...
The significance of writing order Reduce browser ...
In HTML pages, visual elements such as buttons an...
If you use docker for large-scale development but...