I have a MySQL database which holds one column years_valid_for as bigint and another column completion_date as datetime(6). I have to subtract bigint columns number as years.
e.g. years_valid_for is 4 and completion_date is 2023-06-07. I have to subtract 4 years from 2023-06-07 and get 2019-06-07.
Is it possible? If so, how?
I have tried DATE_SUB function but could not achieve the expected result due to syntax errors
2
Answers
You can do it as follows :
Demo here
Syntax:- DATE_SUB(date, INTERVAL value interval)