Skip to content

Instantly share code, notes, and snippets.

@RohanBhanderi
Created December 14, 2020 02:31
Show Gist options
  • Save RohanBhanderi/ab41bdc49ecbad4c0462bd07e690f85f to your computer and use it in GitHub Desktop.
Save RohanBhanderi/ab41bdc49ecbad4c0462bd07e690f85f to your computer and use it in GitHub Desktop.
Postgrsql dates days
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