Last active
June 15, 2016 13:28
-
-
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
This file contains 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
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