days in a given month.

# Thread: days in a given month.

1. Senior Member
Join Date
Dec 1969
Posts
935

## days in a given month.

Hi all,<BR><BR>how do I know how much days are in a given month and which date is which day??<BR><BR>let&#039;s say I get this month (july) as the query, I want to know the number of days (31) and which day is the first of july.<BR><BR>I want to create a calender so I knida need this info..<BR><BR>thanks a lot.

2. Senior Member
Join Date
Dec 1969
Posts
11,334

## RE: days in a given month.

Well, you always know how many days are in the month, with the exception of Feb. Hard code it.<BR><BR>For days, check the docs:<BR><BR>foistOvDaMonf = WeekdayName(Weekday(#7/1/2004#))

3. Senior Member
Join Date
Dec 1969
Posts
935

## RE: days in a given month.

first of all thanks for the quick response...<BR>the thing with the first day of the month works great, thanks.<BR><BR>about the number of days per month, yes I do know how much days are in any month but there&#039;s no way to get that info with out using an array or a bunch of "if"s????

4. Senior Member
Join Date
Dec 1969
Posts
11,334

## RE: days in a given month.

I would imagine there are thousands of examples out there if you did a quick search... but for JS you could simply do:<BR><BR>function totalDays(m){<BR> switch (m){<BR> case 0: //js months start at 0<BR> return 31;<BR> case 1:<BR> //do some checking here for a leap year... I *think*<BR> //you&#039;ll return 20 if the year is evenly divisible by 4 and<BR> //not 100? Or something like that...<BR> case 3:<BR> return 30;<BR> }<BR>}<BR><BR><BR>and so on....

5. Senior Member
Join Date
Dec 1969
Posts
11,334

## Here's the leaps

Leap Year Calculation <BR><BR><BR>1. Years divisible by four are leap years, unless...<BR>2. Years also divisible by 100 are not leap years, except...<BR>3. Years divisible by 400 are leap years.<BR><BR> <BR><BR>So not hard to code...<BR> if ((y % 4 == 0)) && ((y % 100 != 0) &#124&#124 (y % 400 == 0)))<BR><BR>should work. Untested.

6. Senior Member
Join Date
Dec 1969
Posts
96,118

## Triple blech...

VBScript has a function created JUST for this purpose!<BR><BR>DateSerial( )<BR><BR>&#060;%<BR>dt = ... input any date ...<BR><BR>NumberOfDays = DateSerial( Year(dt), Month(dt)+1, 0 )<BR>WeekdayOfFirstOfMonth = Weekday( DateSerial( Year(dt), Month(dt), 1 ) )<BR>%&#062;<BR><BR>Or WeekdayName(WeekDay( ... ) ) if you want text form.<BR><BR>Yes, it handles any month in any year, even leap years.<BR><BR>

7. Senior Member
Join Date
Dec 1969
Posts
935

## RE: days in a given month.

yeah well, that&#039;s what I thought....<BR>I&#039;m using vbscript but the idea is the same.<BR><BR>hoped that there&#039;s a function in asp that will give me the answer.<BR><BR>thanks.

8. Senior Member
Join Date
Dec 1969
Posts
2,885

## RE: I think you forgot something??

One more step perhaps:<BR>NumberOfDays = Day(DateSerial( Year(dt), Month(dt)+1, 0 )) <BR>

9. Senior Member
Join Date
Dec 1969
Posts
2,885

## RE: days in a given month.

10. Senior Member
Join Date
Dec 1969
Posts
11,334

## I assumed client side JS <nm>

boo

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•