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);

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.