Hi Friends,
I have 2 display month between 2 dates
For eg.I have StartDate=1/1/2011 and EndDate=15/5/2011
It will display me:
January February March April May
Display Month name using Sql Querry
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.


ShankeyRank #972 · 2.1K reputationPosted Feb 2, 2011, 9:29 PM EST
Hope this will help you,
Declare
@sd date,
@ed date
begin
set @sd=CONVERT(date,'1/1/2011');
set @ed=CONVERT(date,'5/15/2011');
while (@sd < @ed)
begin
SELECT DATENAME(month, @sd)
SET @sd = DATEADD(MONTH,1,@sd);
End
End
Thanks,
Shankey
Manikavelu VelayuthamRank #413 · 6K reputationPosted Feb 2, 2011, 9:31 PM EST
FLOAT
F1: BEGIN ATOMIC
RETURN 12 * (year(d1) - year(d2)) + month(d1)- month(d2) + ( TIMESTAMPDIFF(2, CHAR(d1 - (d2 + (12*(year(d1) - year(d2)) + month(d1) - month(d2)) MONTHS))) / 2678400.0 );--
END@
SELECT dbo.months_between(firstdate, seconddate)
Above will return the months between the two dates.