Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

MySQL subtract bigint value as year

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I have tried DATE_SUB function but could not achieve the expected result due to syntax errors

>Solution :

You can do it as follows :

SELECT *, completion_date - INTERVAL years_valid_for YEAR 
FROM mytable

Demo here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading