SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Get end of the month
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

jrobin747
Starting Member

USA
48 Posts

Posted - 07/25/2013 :  17:34:46  Show Profile  Reply with Quote
I am using sql server 2005. I am trying to create a function that gives me the end of the month. I know how to get the current date.

What I ultimately want to do is display how many days are left in the month no matter what month I am currently in.

Upon research I found EOMONTH
http://technet.microsoft.com/en-us/library/hh213020.aspx

But that doesn't work for server 2005.

James K
Flowing Fount of Yak Knowledge

3559 Posts

Posted - 07/25/2013 :  17:38:45  Show Profile  Reply with Quote
-- end of current month
SELECT DATEADD(mm,DATEDIFF(mm,0,GETDATE())+1,-1)
-- end of last month
SELECT DATEADD(mm,DATEDIFF(mm,0,GETDATE())+0,-1)
-- end of next month
SELECT DATEADD(mm,DATEDIFF(mm,0,GETDATE())+2,-1)
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30113 Posts

Posted - 07/25/2013 :  17:49:52  Show Profile  Visit SwePeso's Homepage  Reply with Quote
SELECT DATEADD(MONTH, DATEDIFF(MONTH, '18991231', GETDATE()), '18991231')
SELECT DATEADD(MONTH, DATEDIFF(MONTH, '19000131', GETDATE()), '18991231')
SELECT DATEADD(MONTH, DATEDIFF(MONTH, '18991231', GETDATE()), '19000131')



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page

jrobin747
Starting Member

USA
48 Posts

Posted - 07/25/2013 :  17:53:43  Show Profile  Reply with Quote
Perfect Thanks
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000