1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-03 07:08:01 +00:00
Files
til/postgres/using-intervals-to-offset-time.md

498 B

Using Intervals To Offset Time

Postgres Intervals can be used with time as a way of determining a standard offset. For instance, I can concisely determine what the time was 2 hours earlier with

> select now() - '2 hours'::interval as earlier;
            earlier
-------------------------------
 2015-06-12 21:17:43.678822-05

or similarly

> select now() - interval '2 hours' as earlier;
            earlier
-------------------------------
 2015-06-12 21:17:43.678822-05