-
Notifications
You must be signed in to change notification settings - Fork 0
MySQL
This is a function that adds a unit of time to an existing date. The format of the function is: DATE_ADD(date, INTERVAL value, addunit) Parameters for DATE_ADD() function: date: starting date to which you want add time value: the amount of time/days/month etc to add. This number can be positive or negative, depending on desired results. To get a time before the date supplied, value should be negative. addunit: This is the unit of time to add. The date only options are: DAY, WEEK, MONTH, QUARTER, YEAR. The single unit of time only options are: MICROSECOND, SECOND, MINUTE, HOUR. The multiple units of time/date options (both units are changed by the same value supplied above): SECOND_MICROSECOND, MINUTE_MICROSECOND, MINUTE_SECOND, HOUR_MICROSECOND, HOUR_SECOND, HOUR_MINUTE, DAY_MICROSECOND, DAY_SECOND, DAY_MINUTE, DAY_HOUR, YEAR_MONTH.
If a time after the supplied data is needed, then the value should be positive. Note, for any units that use time, if you do not supply a time (see example below on how to add time), it will default to 12:00 am.
Examples of DATE_ADD SELECT DATE_ADD("2020-01-01", INTERVAL 47 DAY); SELECT DATE_ADD("2019-12-01 09:34:21", INTERVAL -30 DAY_HOUR);