Created
December 14, 2020 02:31
-
-
Save RohanBhanderi/ab41bdc49ecbad4c0462bd07e690f85f to your computer and use it in GitHub Desktop.
Postgrsql dates days
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 compr_as AS ( | |
SELECT s as created | |
FROM generate_series( -- this would produce timestamps with 20 minutes step | |
(now() - '20 days'::interval)::date, | |
(now() + '20 days'::interval)::date, | |
'20 minutes'::interval) AS s | |
) | |
SELECT to_char( created, 'DY'::TEXT), created, | |
date_trunc('week', CURRENT_DATE - interval '1 week') as start_dt, | |
date_trunc('week', CURRENT_DATE) as end_dt | |
FROM compr_as | |
WHERE TRUE | |
AND created >= date_trunc('week', CURRENT_DATE - interval '1 week') | |
AND created < date_trunc('week', CURRENT_DATE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment