Last active
September 22, 2018 20:02
-
-
Save ichux/369c0efe9c5cde5596d7a6e9c8b778eb to your computer and use it in GitHub Desktop.
Get the first and last date of the present month in Postgres
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| WITH first_day AS (SELECT date_trunc('MONTH', NOW()) :: DATE), | |
| last_day AS (SELECT (date_trunc('MONTH', (SELECT * FROM first_day)) + INTERVAL '1 MONTH' - | |
| INTERVAL '1 DAY') :: DATE) | |
| SELECT first_day.*, last_day.* | |
| FROM first_day, | |
| last_day; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| WITH first_day AS (SELECT date_trunc('MONTH', NOW()) :: DATE AS first_date), | |
| last_day AS (SELECT (date_trunc('MONTH', (SELECT * FROM first_day)) + INTERVAL '1 MONTH' - | |
| INTERVAL '1 DAY') :: DATE AS last_date) | |
| SELECT row_to_json(first_last) | |
| FROM (SELECT first_day.*, last_day.* | |
| FROM first_day, | |
| last_day) first_last; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment