Days in month

1. Mark Guest

## Days in month

What&#039s the best way to return how many day&#039s are in a month?<BR><BR>Thanks in advance

2. Search the FAQ Guest

## RE: Days in month

cut and paste:<BR><BR>http://www.4guysfromrolla.com/webtech/faq/Intermediate/faq2.shtml

3. BalletChick Guest

## RE: Days in month

There are at least five ways... here are a couple that rely on intrinsic VBScript functions:<BR><BR>Function LastDay(month, year)<BR>&nbsp;&nbsp;&nbsp; dim intX<BR>&nbsp;&nbsp;&nbsp; for intX = 31 to 28 step -1<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if isdate(month & "/" & intX & "/" & year) then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; exit for<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end if<BR>&nbsp;&nbsp;&nbsp; next<BR>&nbsp;&nbsp;&nbsp; LastDay = intX<BR>End Function<BR><BR><BR>Function LastDay2(Month, Year)<BR>&nbsp;&nbsp;&nbsp; dim intX, dtTest<BR>&nbsp;&nbsp;&nbsp; intX = Month + 1<BR>&nbsp;&nbsp;&nbsp; if intX &#062; 12 then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dtTest = cdate("1/1/" & cstr(year + 1))<BR>&nbsp;&nbsp;&nbsp; else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dtTest = cdate(intX & "/1/" & year)<BR>&nbsp;&nbsp;&nbsp; end if<BR>&nbsp;&nbsp;&nbsp; dtTest = DateAdd("d",-1,dtTest)<BR>&nbsp;&nbsp;&nbsp; LastDay2 = day(dtTest)<BR>end function<BR><BR><BR>You could also do something like this:<BR><BR><BR>Function LastDay3(month, year)<BR><BR>&nbsp;&nbsp;&nbsp; dim intX<BR>&nbsp;&nbsp;&nbsp; intX = int(mid("312831303130313130313031", ((month-1) * 2) + 1, 2))<BR>&nbsp;&nbsp;&nbsp; if month = 2 then<BR>&nbsp;&nbsp;&nbsp; if (year/400 = year400) or ((year mod 4 = 0) and (year mod 100 &#060;&#062; 0)) then<BR>&nbsp;&nbsp;&nbsp; intX = intX + 1<BR>&nbsp;&nbsp;&nbsp; end if<BR>&nbsp;&nbsp;&nbsp; end if<BR>&nbsp;&nbsp;&nbsp; LastDay3 = intX<BR>end function<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
•