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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to find months falls between two dates
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

urzsuresh
Starting Member

India
30 Posts

Posted - 09/30/2010 :  08:35:38  Show Profile  Reply with Quote
Hi,
I need to bring the result ,what r t months falls between two dates.
(i.e)


Eg.1
Declare @FrDate datetime,@ToDate datetime
Set @FrDate ='2010-01-31 17:38:58.577' 
Set @ToDate ='2010-03-01 17:38:58.577'

need Output 
Result
1
2
3

Eg.2 Suppose date is
Declare @FrDate datetime,@ToDate datetime
Set @FrDate ='2010-05-31 17:38:58.577' 
Set @ToDate ='2010-09-01 17:38:58.577'

need Output 
Result
5
6
7
8
9


Can anyone please guide me. how to bring this result


Suri

SwePeso
Patron Saint of Lost Yaks

Sweden
30217 Posts

Posted - 09/30/2010 :  08:40:36  Show Profile  Visit SwePeso's Homepage  Reply with Quote
SELECT * FROM master..spt_values where type = 'p' and number between datepart(month, @frdate) and datepart(month, @todate)



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

Bustaz Kool
Flowing Fount of Yak Knowledge

USA
1677 Posts

Posted - 09/30/2010 :  12:45:50  Show Profile  Reply with Quote
urzsuresh,

What do you want when the date range wraps around to another year (e.g., 2010-09-30 thru 2011-02-02)?

=======================================
In all life one should comfort the afflicted, but verily, also, one should afflict the comfortable, and especially when they are comfortably, contentedly, even happily wrong. -John Kenneth Galbraith, economist (1908-2006)
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.05 seconds. Powered By: Snitz Forums 2000