Skip to content

Instantly share code, notes, and snippets.

@mcgaffin
Last active June 15, 2016 13:28
Show Gist options
  • Save mcgaffin/1e3e223af81c0bdcb8a836d5221dd75a to your computer and use it in GitHub Desktop.
Save mcgaffin/1e3e223af81c0bdcb8a836d5221dd75a to your computer and use it in GitHub Desktop.
Find number of days in any month modded by some day-of-month
postgresql
----
select 31 % (SELECT
DATE_PART(
'days',
DATE_TRUNC('month', now() :: DATE) + '1 MONTH' :: INTERVAL - '1 DAY' :: INTERVAL
)
)::integer
redshift
---
In addition to finding the number of days in a month, it mods a number against that.
select (14 % (
SELECT to_number(
date_part(
days,
dateadd(
DAY,
- 1,
dateadd(
MONTH,
1,
DATE_TRUNC('month', getdate())
)
)
), '99')
)) = 13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment