Today I Learned

hashrocket A Hashrocket project

Day Of Week For A Date

Given a date in PostgreSQL

> 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

> select date_part('dow', '2050-1-1'::date);
 date_part
-----------
         6

The days of week are 0 through 6, 0 being Sunday and 6 being Saturday.

source

See More #sql TILs
Looking for help? Hashrocket developers believe that data quality is as important as code quality. We enjoy all the challenges of relational databases, from finding the fastest index, to structuring data to fit the needs of an application. We're eager to share our experiences; check out PG Casts, our series of free PostgreSQL screencasts.