DATE_ADD
is a date function in SQL that adds a specified interval to a date and returns the resulting date. The syntax of DATE_ADD
function is:
DATE_ADD(date, INTERVAL value unit)
where date
is the initial date, value
is the number of intervals to add, and unit
is the unit of the interval, such as DAY
, MONTH
, YEAR
, HOUR
, MINUTE
, SECOND
, etc.
If you want to add or subtract 1 day from any date try below query
select DATE_ADD('2023-01-01',INTERVAL 1 DAY) as new_date
//Output
2023-01-02
//also try below query to subtract 1 Day
select DATE_ADD('2023-01-01',INTERVAL -1 DAY) as new_date
//Output
2022-12-31
If you want to add or subtract 1 month from any date try below query
select DATE_ADD('2023-01-01',INTERVAL 1 MONTH) as new_date
//Output
2023-02-01
//also try below query to subtract 1 Day
select DATE_ADD('2023-01-01',INTERVAL -1 MONTH) as new_date
//Output
2022-12-01
If you want to add or subtract 1 year from any date try below query
select DATE_ADD('2023-01-01',INTERVAL 1 YEAR) as new_date
//Output
2024-01-01
//also try below query to subtract 1 Day
select DATE_ADD('2023-01-01',INTERVAL -1 YEAR) as new_date
//Output
2022-01-01
You can also use DATE_ADD multiple times on same query just like id you want to add 1 year and subtract 1 day
select DATE_ADD(DATE_ADD('2023-01-01',INTERVAL 1 YEAR),INTERVAL -1 DAY) as new_date
//Output
2023-12-31