1. Time difference functions (TIMESTAMPDIFF, DATEDIFF) You need to use MySQL to calculate the time difference, use TIMESTAMPDIFF, DATEDIFF, and record the experimental results --0 select datediff(now(), now()); --2 select datediff('2015-04-22 23:59:00', '2015-04-20 00:00:00'); --2 select datediff('2015-04-22 00:00:00', '2015-04-20 23:59:00'); --1 select TIMESTAMPDIFF(DAY, '2015-04-20 23:59:00', '2015-04-22 00:00:00'); --2 select TIMESTAMPDIFF(DAY, '2015-04-20 00:00:00', '2015-04-22 00:00:00'); --2 select TIMESTAMPDIFF(DAY, '2015-04-20 00:00:00', '2015-04-22 12:00:00'); --2 select TIMESTAMPDIFF(DAY, '2015-04-20 00:00:00', '2015-04-22 23:59:00'); --71 select TIMESTAMPDIFF(HOUR, '2015-04-20 00:00:00', '2015-04-22 23:00:00'); --4260 select TIMESTAMPDIFF(MINUTE, '2015-04-20 00:00:00', '2015-04-22 23:00:00'); For a description of TIMESTAMPDIFF, see http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_timestampdiff If you want to know what other units TIMESTAMPDIFF can return data in, refer to the description of TIMESTAMPADD: http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_timestampadd 2. Date conversion calculation functions (date_add, day, date_format, str_to_date) -- Use date and string conversion to calculate the first day of the current month and the first day of the next month select curdate() as 'current date', DATE_FORMAT(curdate(), '%Y-%m') as 'Current month', str_to_date(concat(DATE_FORMAT(curdate(), '%Y-%m'), '-01'), '%Y-%m-%d') as 'The first day of the current month', date_add(str_to_date(concat(DATE_FORMAT(curdate(), '%Y-%m'), '-01'), '%Y-%m-%d'), interval 1 month) as 'The first day of the next month'; -- The last day of the current month select last_day(curdate()); -- The first day of the next month select date_add(last_day(curdate()), interval 1 day); -- What day of the month is the current day? select day(curdate()); -- First day of the month select date_add(curdate(), interval 1-(day(curdate())) day); The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: The best explanation of HTTPS
>>: The use and methods of async and await in JavaScript
I recently used Dreamweaver to make a product pres...
1. Docker installation and settings #Install Cent...
Correct answer Using useRouter : // router path: ...
Arial Arial is a sans-serif TrueType font distribu...
This article mainly explains how to install the M...
I spent a day on it before this. Although Seata i...
1. Download the successfully generated icon file, ...
Unzip the Maven package tar xf apache-maven-3.5.4...
[LeetCode] 180. Consecutive Numbers Write a SQL q...
MySQL database basic syntax DDL Operations Create...
This article example shares the specific code of ...
Table of contents 1. Introduction 2. Direct recov...
Table of contents 1. Implementation process of qu...
This is to commemorate the 4 pitfalls I stepped o...
Preface Starting from React 16, the concept of Er...