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

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -