From e1b9a6ac9ea35f1ce1d96b20b1e002046237c556 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Sat, 30 Jan 2016 12:29:11 -0600 Subject: [PATCH] Add Constructing A Range Of Dates as a postgres til --- README.md | 1 + postgres/constructing-a-range-of-dates.md | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 postgres/constructing-a-range-of-dates.md diff --git a/README.md b/README.md index 02d2f85..108f82d 100644 --- a/README.md +++ b/README.md @@ -132,6 +132,7 @@ _310 TILs and counting..._ - [Checking The Type Of A Value](postgres/checking-the-type-of-a-value.md) - [Compute Hashes With pgcrypto](postgres/compute-hashes-with-pgcrypto.md) - [Configure The Timezone](postgres/configure-the-timezone.md) +- [Constructing A Range Of Dates](postgres/constructing-a-range-of-dates.md) - [Count Records By Type](postgres/count-records-by-type.md) - [Create A Composite Primary Key](postgres/create-a-composite-primary-key.md) - [Create hstore From Two Arrays](postgres/create-hstore-from-two-arrays.md) diff --git a/postgres/constructing-a-range-of-dates.md b/postgres/constructing-a-range-of-dates.md new file mode 100644 index 0000000..2443645 --- /dev/null +++ b/postgres/constructing-a-range-of-dates.md @@ -0,0 +1,17 @@ +# Constructing A Range Of Dates + +PostgreSQL offers a number of range types including the `daterange` type. +This can be constructed using the `daterange()` function with two strings +representing the lower and upper bounds of the date range respectively. + +```sql +> select daterange('2015-1-1','2015-1-5'); + daterange +------------------------- + [2015-01-01,2015-01-05) +``` + +The lower bound is inclusive -- indicated by the `[` character -- and the +upper bound is exclusive -- indicated by the `)` character. + +[source](http://www.postgresql.org/docs/current/static/rangetypes.html)