MySQL date plus minus

1. addtime() is the date plus the specified number of seconds

select addtime(now(),1); -- Plus 1 second

2. adddate() can be used in two ways. The second parameter is to add the specified number of days to the date, and the second parameter is to add the specified interval time to the date

select adddate(now(),1); -- Plus 1 day
select adddate(now(), interval 1 day); -- Plus 1 day

select adddate(now(), interval 1 hour); --Plus 1 hour

select adddate(now(), interval 1 minute); -- Plus 1 minute

select adddate(now(), interval 1 second); -- Plus 1 second

select adddate(now(), interval 1 microsecond); -- Plus 1 ms

select adddate(now(), interval 1 week); -- Plus 1 week

select adddate(now(), interval 1 month); -- Plus January

select adddate(now(), interval 1 quarter); -- Plus one season

select adddate(now(), interval 1 year); -- Plus 1 year

3. date_add() adds a time interval for the date, which can only use the interval time as a parameter, and the usage is the same as that of adddate()

select date_add(now(), interval 1 day); -- Plus 1 day

select date_add(now(), interval 1 hour); -- Plus 1 hour

select date_add(now(), interval 1 minute); -- Plus 1 minute

select date_add(now(), interval 1 second); -- Plus 1 second

select date_add(now(), interval 1 microsecond); -- Plus 1 ms

select date_add(now(), interval 1 week); -- Plus 1 week

select date_add(now(), interval 1 month); -- Plus January

select date_add(now(), interval 1 quarter); -- Plus one season

select date_add(now(), interval 1 year); -- Plus 1 year

4. Time () subtracts the specified number of seconds from the date

select subtime(now(), 1); -- Minus 1 second

5. The usage of the date () function is the same as that of the adddate() function. There are two usages. The second parameter is to directly fill in the number, subtract the specified days from the date, and the interval, subtract the specified interval from the date

select subdate(now(),1); -- Minus 1 day
select subdate(now(), interval
1 day); -- Minus 1 day select subdate(now(), interval 1 hour); --reduce1 hour select subdate(now(), interval 1 minute); -- Minus 1 minute select subdate(now(), interval 1 second); -- Minus 1 second select subdate(now(), interval 1 microsecond); -- Minus 1 ms select subdate(now(), interval 1 week); -- Minus 1 week select subdate(now(), interval 1 month); -- Less January select subdate(now(), interval 1 quarter); -- Minus one season select subdate(now(), interval 1 year); -- Less 1 year

6. The usage of date ﹣ sub() is the same as that of date ﹣ add(). Subtract a time interval from the date, which can only use the interval time as a parameter

select date_sub(now(), interval 1 day); -- Minus 1 day

select date_sub(now(), interval 1 hour); --Minus 1 hour

select date_sub(now(), interval 1 minute); -- Minus 1 minute

select date_sub(now(), interval 1 second); -- Minus 1 second

select date_sub(now(), interval 1 microsecond); -- Minus 1 ms

select date_sub(now(), interval 1 week); -- Minus 1 week

select date_sub(now(), interval 1 month); -- Less January

select date_sub(now(), interval 1 quarter); -- Minus 1 season

select date_sub(now(), interval 1 year); -- Less 1 year

Tags: MySQL less

Posted on Fri, 15 May 2020 10:26:49 -0400 by jwrightnisha