Home > OS >  Postgres change year from one year to another year
Postgres change year from one year to another year

Time:02-04

I have tried to use the following in PostgreSQL but it adds about 2000 years to the year. I am needing to change the year from 2096 to 2001 or 2000 doesn't really matter. When I run this it adds about 2000 years to the year 2096 and makes it 4096.

UPDATE module_warrants 
  SET receiveddate = receiveddate   MAKE_INTERVAL(YEARS :=2096 -96) 
where receiveddate >= '01-01-2094'

Expect the year to decrease by 96 years to 2000 from 2096.

CodePudding user response:

The expression MAKE_INTERVAL(YEARS :=2096 -96) is adding 2000 years (2096-96) to the current value.

But you want to subtract the number:

receiveddate - make_interval(years => 96)

or

receiveddate - interval '96 years'

CodePudding user response:

receiveddate - interval '96 years' That was it - right in front of me and missed it. Thanks.

  • Related