I tried to do SQL Subtract exactly a year but the syntax in PSQL didn't work. In my case dates were imported with 2 digit years so they all have birthdays off by 1900 years.
UPDATE patients SET birthday = dateadd(year, 100, getdate(birthday)
throws:
ERROR: syntax error at or near "table"
LINE 1: UPDATE table SET datefield = DATE_ADD(datefield, INTERVAL 1 ...
This works in PostgreSQL by simply using INTERVAL and passing in a string of increment values and type (seconds, minutes, hours, days, months, years) etc.
UPDATE patients SET birthday = birthday + INTERVAL '1900 years';
Found idea here https://www.postgresql.org/docs/9.1/static/functions-datetime.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With