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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Months Between 2 dates

Author  Topic 

msenthilrajanmca
Starting Member

3 Posts

Posted - 2008-05-24 : 08:14:17
Hi Friends,

i need a Month name between 2 dates...

Example :

If i give start date(MM/dd/yyyy) is 03/20/2008
and End Date(MM/dd/yyyy) is 05/24/2008)

The Output Should be

March,
April,
May

How can i get this...

Thank you...

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2008-05-24 : 08:34:19
Here's one way:

declare @st datetime
,@end datetime
select @st = '03/20/2008'
,@end = '05/24/2008'

select MonthName = datename(month, dateadd(month, number, @st))
from master..spt_values
where type = 'p'
and number <= datediff(month, @st, @end)


output:
MonthName
------------------------------
March
April
May


Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -