Calendar algorithm

1. Clint S. Guest

## Calendar algorithm

I&#039;m making an ASP calendar and I can&#039;t figure out how to get the first day of the month start on the correct day of the week. Like April 1 was on a Sunday, March 1 was on a Thursday, and May 1 will be on a Tuesday. There has to be some sort of algorithm to do this. I looked on the internet and some said they got an alogrithm out of a book called the Rainbow Mathematics Encyclopedia but I can&#039;t find that book. The person who gave the title must have been wrong because I can&#039;t find that book anywhere on the internet. Thanks for the help.

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

## I wrote demo on our Web site...

http://www.chilisoft.com/caspsamp/calendar.asp<BR><BR>It&#039;s pretty clear and easy to use. But be kind! I think it was the first ASP page I ever wrote, so it may not be real efficient.<BR><BR>But I also provide a version that is all browser-side (in JavaScript code) on my "home" site: <BR>http://www.ClearviewDesign.com/NEWBIE<BR><BR>

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

## Oh, blech! Time to rewrite!

All this code:<BR><BR><BR> &#039;<BR> &#039; figure out number of days in the month<BR> &#039;<BR> If ( themonth = 2 ) Then<BR>&nbsp; &nbsp; &#039; February -- assume 28 day month<BR>&nbsp; &nbsp; daysInMonth = 28<BR>&nbsp; &nbsp; &#039; But then see if should be 29 day<BR>&nbsp; &nbsp; If theyear = ( 4 * Int( theyear / 4 ) ) Then<BR>&nbsp; &nbsp; &nbsp; &nbsp; daysInMonth = 29<BR>&nbsp; &nbsp; &nbsp; &nbsp; &#039; Every 4 years is a leap year...EXCEPT<BR>&nbsp; &nbsp; &nbsp; &nbsp; If theyear = ( 100 * Int( theyear / 100 ) ) Then<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; daysInMonth = 28<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039; Every 100 years is NOT a leap year...EXCEPT<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If theyear = ( 400 * Int( theyear / 400 ) ) Then<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039; Every 400 years IS a leap year<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; daysInMonth = 29<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End If<BR>&nbsp; &nbsp; &nbsp; &nbsp; End If<BR>&nbsp; &nbsp; End If<BR> Else<BR>&nbsp; &nbsp; If ( themonth=4 or themonth=6 or themonth=9 or themonth=11 ) Then<BR>&nbsp; &nbsp; &nbsp; &nbsp; daysInMonth = 30<BR>&nbsp; &nbsp; Else<BR>&nbsp; &nbsp; &nbsp; &nbsp; daysInMonth = 31 <BR>&nbsp; &nbsp; End If<BR> End If<BR><BR>Can be replace with just this:<BR><BR>&nbsp; &nbsp; daysInMonth = Day( DateSerial( theYear, theMonth+1, 0 ) )<BR><BR>Really! Honest. See, I&#039;ve learned a little bit since then.<BR><BR>

4. Heaven's Martini Guest

## can't change history

Ufda,<BR><BR>Good to know even you wrote code like that.<BR><BR>hehe.<BR><BR>even superman had kryptonite

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

## Unless you write the history book...

But too true!<BR><BR>I was conditioned to using C/C++/Pascal, and none of them have the handy Date functions that VBS has! <BR><BR>DateSerial is a woefully overlooked function! I had to implement it for the ChiliSoft version of ASP (writing in C++, that is), and it was a pain! But the results are well worth it in the end!

#### Posting Permissions

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