By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,559 Members | 1,150 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,559 IT Pros & Developers. It's quick & easy.

to generate all the dates for a given month and year..

P: 30
hi frenz,

I want to display all the dates and day of the given year and month.
For ex; if i choose 2007 and select the month January, i want to generate all the dates for this selection
1/1/2007
2/1/2007
....
...
..
31/1/2007,
and the day name (monday,tuesday...) for all the generated dates. Also, need to check for the leapyear, and generate the dates accordingly. Pls provide some kind-a help. its urgent. I'm able to generate the dates, but need to display the dayname and chk for leap year.

Cheers,
jai
Mar 28 '07 #1
Share this Question
Share on Google+
2 Replies


iburyak
Expert 100+
P: 1,017
Try this:

[PHP]Declare @year int, @month int, @StartDate datetime, @EndDate datetime
Declare @Date datetime

SET @year = 2008
SET @month = 2
SET @StartDate = cast(cast(@month as varchar(10)) + '-1-' + cast(@year as varchar(10)) as datetime)
SET @EndDate = dateadd(m,1,@StartDate)

DECLARE @temp TABLE (Date_Time varchar(50))

SET @Date = @StartDate

While @Date < @EndDate
BEGIN

INSERT INTO @temp
SELECT DATENAME (dw, @Date) + ', ' + convert(varchar(30), @Date, 110)

SELECT @Date = dateadd(d,1, @Date)
END

SELECT * from @temp[/PHP]


Don't worry about leap year it will be handled with internal calendar.

Good Luck.
Mar 28 '07 #2

P: 30
Hi iburyak,

Thanks for your help. Sorry for the late reply. i was also working on the code and got the desired output. Once again, thank you.

Cheers,.
jai
Try this:

[PHP]Declare @year int, @month int, @StartDate datetime, @EndDate datetime
Declare @Date datetime

SET @year = 2008
SET @month = 2
SET @StartDate = cast(cast(@month as varchar(10)) + '-1-' + cast(@year as varchar(10)) as datetime)
SET @EndDate = dateadd(m,1,@StartDate)

DECLARE @temp TABLE (Date_Time varchar(50))

SET @Date = @StartDate

While @Date < @EndDate
BEGIN

INSERT INTO @temp
SELECT DATENAME (dw, @Date) + ', ' + convert(varchar(30), @Date, 110)

SELECT @Date = dateadd(d,1, @Date)
END

SELECT * from @temp[/PHP]


Don't worry about leap year it will be handled with internal calendar.

Good Luck.
Apr 4 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.