From 91568034883c21ad3feacbfcd4ec542dba1bbca5 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Fri, 29 Jan 2016 21:37:28 -0600 Subject: [PATCH] Add Day Of Week For A Date as a postgres til --- README.md | 1 + postgres/day-of-week-for-a-date.md | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 postgres/day-of-week-for-a-date.md diff --git a/README.md b/README.md index e4dcdf9..1afd820 100644 --- a/README.md +++ b/README.md @@ -136,6 +136,7 @@ _310 TILs and counting..._ - [Create A Composite Primary Key](postgres/create-a-composite-primary-key.md) - [Create hstore From Two Arrays](postgres/create-hstore-from-two-arrays.md) - [Creating Conditional Constraints](postgres/creating-conditional-constraints.md) +- [Day Of Week For A Date](postgres/day-of-week-for-a-date.md) - [Default Schema](postgres/default-schema.md) - [Defining Arrays](postgres/defining-arrays.md) - [Edit Existing Functions](postgres/edit-existing-functions.md) diff --git a/postgres/day-of-week-for-a-date.md b/postgres/day-of-week-for-a-date.md new file mode 100644 index 0000000..0540076 --- /dev/null +++ b/postgres/day-of-week-for-a-date.md @@ -0,0 +1,22 @@ +# Day Of Week For A Date + +Given a `date` in PostgreSQL + +```sql +> select '2050-1-1'::date; + date +------------ + 2050-01-01 +``` + +you can determine the day of the week for that date with the `date_part()` +function + +```sql +> select date_part('dow', '2050-1-1'::date); + date_part +----------- + 6 +``` + +[source](http://www.postgresql.org/docs/current/static/functions-datetime.html)