PostgreSQL – Update DATETIME with offset

Ever landed into a situation where the time entered in the PostgreSQL DB was in UTF and you need to update the entire table by the offset, say -8 hours. A simple UPDATE query can be executed to achieve the results:

UPDATE tablename 
SET datetime_column = datetime_column - CAST('8 hours' AS INTERVAL);

OR

To add an offset to the fields, it could be hours, minutes and even days

UPDATE tablename 
SET datetime_column = datetime_column + CAST('14 days' AS INTERVAL);
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s