Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
jrobin747
Starting Member
48 Posts |
Posted - 2013-07-25 : 17:34:46
|
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.aspxBut that doesn't work for server 2005. |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-07-25 : 17:38:45
|
[code]-- end of current monthSELECT DATEADD(mm,DATEDIFF(mm,0,GETDATE())+1,-1)-- end of last monthSELECT DATEADD(mm,DATEDIFF(mm,0,GETDATE())+0,-1)-- end of next monthSELECT DATEADD(mm,DATEDIFF(mm,0,GETDATE())+2,-1)[/code] |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2013-07-25 : 17:49:52
|
[code]SELECT DATEADD(MONTH, DATEDIFF(MONTH, '18991231', GETDATE()), '18991231')SELECT DATEADD(MONTH, DATEDIFF(MONTH, '19000131', GETDATE()), '18991231')SELECT DATEADD(MONTH, DATEDIFF(MONTH, '18991231', GETDATE()), '19000131')[/code] Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA |
|
|
jrobin747
Starting Member
48 Posts |
Posted - 2013-07-25 : 17:53:43
|
Perfect Thanks |
|
|
|
|
|
|
|