total number of days in a month

# Thread: total number of days in a month

1. zig Guest

## total number of days in a month

can anyone help how to find the total days in a given month. i need to dynamically fill in a list box based on the number of days in the current month.

2. Steve Cimino Guest

## RE: total number of days in a month

Use an array. When the current month is selected, you can point to that dimension/element in your array (ie, if month = oct, max days are 31)<BR><BR>There is an example with free source code at http://javascript.internet.com

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

## VBS makes it even easier:

&nbsp;<BR>&#060;%<BR>theMonth = 7 &#039 or whatever month you are referring to<BR>theYear = 2000 &#039 or whatever year you are referring to<BR>&#039<BR>numberOfDaysInMonth = Day( DateSerial( theYear, theMonth + 1, 0 ) )<BR>%&#062;<BR><BR>That&#039s a sneaky trick, but if you read the docs for DateSerial, you&#039ll see why it works. <BR><BR>You go "forward" one month (the +1), but then you end up going back a day because you use 0 for the day-of-the-month (when 1 is the first day, so 0 means go back a day!).<BR><BR>Note that this properly takes care of Leap Year, as well.<BR><BR>Here&#039s a little ASP page that demos it all working:<BR><BR>*********** FILE: DaysPerMonth.asp ***********<BR><BR>&LT;HTML&#062;&LT;BODY&#062;<BR ><BR>&LT;%<BR>For y = 2000 to 2001<BR>&nbsp;&nbsp;&nbsp;&nbsp;For m = 1 to 12<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;dpm = Day( DateSerial( y, m+1, 0 ) )<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;Response.Write m & "/" & y & " has " & dpm & "days&LT;BR&#062;" & vbNewLine<BR>&nbsp;&nbsp;&nbsp;&nbsp;Next<BR>Next< BR>%&#062;<BR><BR>&LT;/BODY&#062;&LT;/HTML&#062;<BR><BR><BR>

#### Posting Permissions

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