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
Table of contents 1. Introduction 2. Main text 2....
Table of contents 1. Object 1.1 What is an object...
Recently, when using Apple.com/Ebay.com/Amazon.co...
Due to the initial partitioning of the system, th...
First download JDK. Here we use jdk-8u181-linux-x...
HTML validate refers to HTML validation. It is the...
CI/CD Overview CI workflow design Git code versio...
Table of contents nextTick Mixins $forceUpdate se...
1. Download the successfully generated icon file, ...
This article example shares the specific code of ...
Table of contents Preface VMware clone virtual ma...
1. Link layout of the new site homepage 1. The loc...
Look at the code first #/bin/sh datename=$(date +...
How to define and use: Use the slot tag definitio...
Sometimes we may need to run some commands on a r...