Let's look at an example:
Select Now (), now () +0;
You can see that the now () function can return a time or return a number to see how you use it. If you increase or decrease relative to the current time, you cannot add or subtract a number directly but you need a specific function. such as Date_add () or date_sub (), the former represents an increase, the latter represents a decrease. Its specific use methods are Date_add (Date,interval expr uint) and date_sub (Date,interval expr uint). Examples are as follows:
Select Now () as now,
Date_add (now (), Interval 1 day) as tomorrow,
Date_sub (now (), Interval 1 day) as yesterday;
Where expr can be positive or negative, you can use Date_add () to complete the work of Date_sub (). Examples are as follows:
There is one more question, if it is a leap month, how are these two functions handled?? The default behavior for MySQL is this: if the target year is a leap month, the returned date is February 29, and vice versa is February 28. Examples are as follows:
In the example above, using the Year,day data type can also use data types such as microsecond, second, minute, hour, week, month, and so on.
MySQL time plus and minus function