Skip to content

Instantly share code, notes, and snippets.

@sheldonhull
Last active December 16, 2015 06:19
Show Gist options
  • Save sheldonhull/5390417 to your computer and use it in GitHub Desktop.
Save sheldonhull/5390417 to your computer and use it in GitHub Desktop.
common date manipulation to get EOM/BOM values
declare @Date date = getdate()
select
previous_month_bom = dateadd(month, datediff(month, 0, @Date) - 1, 0) --previous_month_bom
,previous_month_eom = dateadd(day, -1, dateadd(month, datediff(month, 0, @Date), 0)) -- previous_month_eom
,bom = dateadd(month, datediff(month, 0, @Date), 0) -- bom
,eom = dateadd(month, datediff(month, 0, @Date) + 1, -1) -- eom
,next_bom = dateadd(month, datediff(month, 0, @Date) + 1, 0) -- next_bom
,next_eom = dateadd(day, -1, dateadd(month, datediff(month, 0, @Date) + 2, 0)) -- next_eom
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment