PostgreSQL how to update only the Year part of the date

Viewed 4345

I have a table in PostgreSQL. This table has a months column and a mydate column. The months has a value of Jan the mydate has a value of 2017-01-01

I want to update that value to 2018-01-01 but I don't want to have to do it by hard coding in the 2018 date. I would like to use a date_part function but I am not sure if I am approaching this correctly.

Here is what I have so far it is not complete I am stuck on what I need to finish this query:

UPDATE tblshopstatus
Set mydate = mydate + date_part('year') -----I am stuck on this line----
WHERE months = 'Jan'

More examples:

In the months column I have all 12 months listed.

In the mydate column I have dates listed as 2017-01-01, 2017-02-01 etc... through the 12 months.

Is there a way to just increase the year to 2018 for all months.

1 Answers
set mydate = mydate + interval '1 year'
Related