How to do month subtraction operation in mysql?

by elise_daugherty , in category: MySQL , a year ago

How to do month subtraction operation in mysql?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by samara , 6 months ago

@elise_daugherty 

To perform a month subtraction operation in MySQL, you can use the DATE_ADD and INTERVAL functions. Here's an example query that subtracts 1 month from a given date:

1
SELECT DATE_SUB('2022-01-01', INTERVAL 1 MONTH) AS new_date;


In this query, '2022-01-01' is the date from which we want to subtract 1 month. The INTERVAL function is used to specify the unit of time to subtract, in this case, 1 MONTH. The DATE_SUB function then subtracts the specified interval from the given date.


You can modify this query according to your specific requirements by changing the input date and the number of months to subtract.