Date and Time Functions

postgres, date, time, db, functions, operators – Apr 05 2019

This a small overview on the date and time functions available for Postgres

• • •

Overview

I was working on an application and I need to query through some dates. I just realized how much more powerful Postgres is for querying dates then using my language. This post will go through examples but the Postgres documents have so much detail and are better for reviewing.

This blog post will get mores updates, as I learn more about these functions.

Getting day of the week

-- isodow
-- The day of the week as Monday (1) to Sunday (7)
-- This is identical to dow except for Sunday. This matches the ISO 8601 day of the week numbering.
SELECT EXTRACT(ISODOW FROM TIMESTAMP '2001-02-18 20:38:40');
Result: 7

-- dow
-- The day of the week as Sunday (0) to Saturday (6)
SELECT EXTRACT(DOW FROM TIMESTAMP '2001-02-18 20:38:40');
Result: 6
Follow on Twitter
Follow on Github