Snippet Alert: Useful dates (eom, bom, etc)
sql-server
Common date values you may need to reference that you may not want to write from scratch each time.
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 Hope this helps someone else!