1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-03 15:18:01 +00:00

Add Using Intervals To Offset Time as a postgres til.

This commit is contained in:
jbranchaud
2015-06-13 11:47:11 -05:00
parent 8b919ba20e
commit fe7e5f816a
2 changed files with 22 additions and 0 deletions

View File

@@ -57,6 +57,7 @@ smart people at [Hashrocket](http://hashrocket.com/).
- [Timestamp Functions](postgres/timestamp-functions.md)
- [Toggling The Pager In PSQL](postgres/toggling-the-pager-in-psql.md)
- [Turning Timing On](postgres/turning-timing-on.md)
- [Using Intervals To Offset Time](postgres/using-intervals-to-offset-time.md)
- [Who Is The Current User](postgres/who-is-the-current-user.md)
- [Word Count for a Column](postgres/word-count-for-a-column.md)

View File

@@ -0,0 +1,21 @@
# 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
```sql
> select now() - '2 hours'::interval as earlier;
earlier
-------------------------------
2015-06-12 21:17:43.678822-05
```
or similarly
```sql
> select now() - interval '2 hours' as earlier;
earlier
-------------------------------
2015-06-12 21:17:43.678822-05
```