sql - Find no of days remaining on current month from given date -
i want calculate number of days remaining given date
ex:
if date '02/01/2016' remaining days on given month '28'
if 03/05/2016 '25' days...
i tried below
select datepart(dd,'03/05/2016') given me 5 days
sqlserver specific since mentioned version well:
select datediff(day,getdate(),dateadd(s,-1,dateadd(mm, datediff(m,0,getdate())+1,0)))
you need find last date of given month , calculating datediff easy,below expression same
dateadd(s,-1,dateadd(mm, datediff(m,0,getdate())+1,0))
on 2012,it easier:
select datediff(day,getdate(),eomonth(getdate()))
Comments
Post a Comment