In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces how to get the current time in MySQL the day before and the day after. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.
MySQL adds a time interval to the date with the date_add () function
MySQL subtracts a time interval from the date using the date_sub () function
The experiments are as follows:
Mysql > select now ()
+-+
| | now () |
+-+
| | 2017-03-15 16:57:30 |
+-+
1 row in set (0.00 sec)
Mysql > set @ dt = now ()
Query OK, 0 rows affected (0.00 sec)
Add one day:
Mysql > select date_add (@ dt, interval 1 day)
+-+
| | date_add (@ dt, interval 1 day) | |
+-+
| | 2017-03-16 16:57:32 |
+-+
1 row in set (0.00 sec)
One day less:
Mysql > select date_sub (@ dt, interval 1 day)
+-+
| | date_sub (@ dt, interval 1 day) | |
+-+
| | 2017-03-14 16:57:32 |
+-+
1 row in set (0.00 sec)
By the same token, an additional hour and a minute can be used:
Select date_add (@ dt, interval 1 hour);-- add one hour
Select date_add (@ dt, interval 1 minute);-- add one minute
Select date_add (@ dt, interval 1 second);-- add one second
Select date_add (@ dt, interval 1 microsecond);-- add a nuance
Select date_add (@ dt, interval 1 week);-- add one week
Select date_add (@ dt, interval 1 month);-- add one month
Select date_add (@ dt, interval 1 quarter); add one quarter (three months)
One hour less, one minute can be used:
Select date_sub (@ dt, interval 1 hour);-- one hour less
Select date_sub (@ dt, interval 1 minute);-- one minute less
Select date_sub (@ dt, interval 1 second);-- one second less
Select date_sub (@ dt, interval 1 microsecond);-- reduce a little bit
Select date_sub (@ dt, interval 1 week);-- one week less
Select date_sub (@ dt, interval 1 month);-- one month less
Select date_sub (@ dt, interval 1 quarter);-reduced by one quarter (three months)
About how to get the current time in MySQL the day before and the day after sharing here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
SYS.USER$ table in Oracle-last password change time, last locked, last expired, creation time, fai
© 2024 shulou.com SLNews company. All rights reserved.