what version of sql are using
works in sql 2012 and above
--15th of this month
select dateadd(day,15,Eomonth(getdate(),-1))
--15th of last month
select dateadd(day,15,Eomonth(getdate(),-2))
--15th of this month
select dateadd(day,15,dateadd(day,-datepart(day,dateadd(month,0,getdate())),dateadd(month,0,getdate())))
--15th of last month
select dateadd(day,15,dateadd(day,-datepart(day,dateadd(month,-1,getdate())),dateadd(month,-1,getdate())))
Hope it Helps!!
No comments:
Post a Comment