When performing some scheduled tasks, such as monthly closing, and encountering cross-year cross-month situations, I think it is more reliable to use the SQL statement to select the time, so we can understand the function of the next time plus minus.
There are two such functions, one plus one minus
Date_add () adds a specified time interval to a date date_sub () subtracts a specified time interval from a date
Take another look at the parameters
Date_sub (Date,interval expr type)
They all have two parameters, one is time, the other is the time interval of the change.
Like the day before the current time.
Select 1 Day);
The type can also be
Microsecondsecondminutehour Day WEEK MONTH QUARTER Year Second_microsecondminute_microsecondminute_secondhour_microsecondhour_secondhour_minuteday_microsecondday_ Secondday_minuteday_houryear_month
Date_add () |
Add a specified time interval to a date |
Date_sub () |
Subtract a specified time interval from a date |
MySQL time plus and minus function