How to convert the calnedar?

# Thread: How to convert the calnedar?

1. Senior Member
Join Date
Dec 1969
Posts
2,768

## How to convert the calnedar?

I have the following code which creates a Monday through Sunday calendar (see diagram below) but I want to convert it to a Sunday through Saturday calendar (see diagram below). How can I do this?<BR><BR>Monday through Sunday = Mon Tue Wed Thu Fri Sat Sun<BR>Sunday through Saturday = Sun Mon Tue Wed Thu Fri Sat<BR><BR>When posting to your server save as mt.asp (at least, .asp and change the form action - VBscript handles the form submittal which is rather poor because it only works in IE - I&#039;ll be changing that).<BR><BR><BR><BR> &#060;%<BR> response.expires=0<BR> Dim CurMonth<BR> Dim CurDay<BR> Dim CurYear<BR> Dim NumOfDays<BR> Dim CurCell<BR> Dim onDay<BR> Dim FoundFirst<BR>Dim FirstDay<BR>Dim cmonth<BR>Dim cyear<BR>Dim rows<BR>Dim i<BR> CurMonth = request.querystring("cmonth")<BR> CurYear = request.querystring("cyear")<BR> CurDay = request.querystring("cday")<BR> if CurMonth = "" Then curMonth = month(date)<BR> if CurYear = "" Then CurYear = year(date)<BR> if CurDay = "" Then CurDay = day(date)<BR> FirstDay = weekday(CurMonth & "/01/" & CurYear) DOES it have something to do with this line?<BR> cmonth = CurMonth<BR> cyear = CurYear<BR> NumOfDays = getlastday(cmonth,cyear)<BR> FoundFirst = False<BR> curcell = 1<BR> onDay = 0<BR> function GetLastDay( tmonth, tyear )<BR> tmonth = tmonth + 1<BR> if tmonth &#062; 12 Then<BR> tmonth = tmonth - 12<BR> tyear = tyear + 1<BR> End if<BR> Dim x<BR> x = DateAdd("d", -1, tmonth & "/01/" & tyear)<BR> GetLastDay = Day( x )<BR> End function<BR> <BR> rows = 5<BR> if firstday &#062;= 5 and numofdays = 31 Then<BR> rows = 6<BR> End if<BR> if firstday &#062;= 6 and numofdays = 30 Then<BR> rows = 6<BR> End if<BR> <BR> function DayOf()<BR> if foundFirst Then<BR> onDay = OnDay + 1<BR> if onDay &#062; NumofDays Then<BR> DayOf = ""<BR> Else<BR> DayOf = onDay<BR> End if<BR> <BR> Else<BR> if curcell = Firstday or firstday = 1 Then foundfirst = True<BR> <BR> if foundFirst Then<BR> onDay = OnDay + 1<BR> if onDay &#062; NumofDays Then<BR> DayOf = ""<BR> <BR> Else<BR> DayOf = onDay<BR> <BR> End if<BR> Else<BR> DayOf = ""<BR> End if<BR> <BR> End if<BR><BR> <BR> End function<BR><BR>function bgcolor()<BR> curcell = curcell + 1<BR> if (OnDay + 1) = int(CurDay) and int(CurMonth) = int(month(date)) and int(CurYear) = year(date) Then <BR> bgcolor = "#666666"<BR> Else<BR> bgcolor = ""<BR> End if<BR>End function<BR> %&#062;<BR> <BR> <BR> &#060;SCRIPT language="VBScript"&#062;<BR> Sub cmonth_onchange<BR> frm.submit<BR> End Sub<BR> Sub cyear_onchange<BR> frm.submit<BR> End Sub<BR> &#060;/SCRIPT&#062;<BR><BR>&#060;div align="center"&#062;<BR> &#060;FORM name=frm method=get action=mt.asp&#062;<BR> &#060;Select name="cmonth"&#062;<BR> &#060;% For i = 1 To 12 %&#062;<BR> &#060;OPTION value="&#060;%=i%&#062;" &#060;%if int(curmonth) = i Then response.write("Selected")%&#062;&#062;&#060;%=mon thname(i)%&#062;&#060;/OPTION&#062;<BR> &#060;% Next %&#062;<BR> &#060;/Select&#062;<BR> &#060;Select name="cyear"&#062;<BR> &#060;% For i = 2050 To 1980 step -1 %&#062;<BR> &#060;OPTION value="&#060;%=i%&#062;" &#060;%if int(curyear) = i Then response.write("Selected")%&#062;&#062;&#060;%=i%& #062;&#060;/OPTION&#062;<BR> &#060;% Next %&#062;<BR> &#060;/Select&#062;<BR> &#060;/FORM&#062;<BR> &#060;/div&#062;<BR><BR><BR>&#060;div align="center" class="calendar"&#062;<BR>&#060;table border="0" cellspacing="4" cellpadding="0" summary="Monthly calendar with links to each day&#039;s posts"&#062;<BR>&#060;caption class="calendarhead"&#062;&#060;%=MonthName(int(cu rmonth))%&#062; &#060;%=int(curyear)%&#062;&#060;/caption&#062;<BR>&#060;tr&#062;<BR>&#060;th abbr="Monday" align="center"&#062;&#060;span class="calendar"&#062;Mon&#060;/span&#062;&#060;/th&#062;<BR>&#060;th abbr="Tuesday" align="center"&#062;&#060;span class="calendar"&#062;Tue&#060;/span&#062;&#060;/th&#062;<BR>&#060;th abbr="Wednesday" align="center"&#062;&#060;span class="calendar"&#062;Wed&#060;/span&#062;&#060;/th&#062;<BR>&#060;th abbr="Thursday" align="center"&#062;&#060;span class="calendar"&#062;Thu&#060;/span&#062;&#060;/th&#062;<BR>&#060;th abbr="Friday" align="center"&#062;&#060;span class="calendar"&#062;Fri&#060;/span&#062;&#060;/th&#062;<BR>&#060;th abbr="Saturday" align="center"&#062;&#060;span class="calendar"&#062;Sat&#060;/span&#062;&#060;/th&#062;<BR>&#060;th abbr="Sunday" align="center"&#062;&#060;span class="calendar"&#062;Sun&#060;/span&#062;&#060;/th&#062;<BR>&#060;/tr&#062;<BR><BR> &#060;% For i = 1 To rows %&#062;<BR> &#060;TR&#062; <BR> &#060;TD bgcolor="&#060;%=bgcolor%&#062;" align="center"&#062;&#060;span class="calendar"&#062;<BR> &#060;%=DayOf%&#062;<BR> &#060;/span&#062;&#060;/TD&#062;<BR> &#060;TD bgcolor="&#060;%=bgcolor%&#062;" align="center"&#062;&#060;span class="calendar"&#062;<BR> &#060;%=DayOf%&#062;<BR> &#060;/span&#062;&#060;/TD&#062;<BR> &#060;TD bgcolor="&#060;%=bgcolor%&#062;" align="center"&#062;&#060;span class="calendar"&#062;<BR> &#060;%=DayOf%&#062;<BR> &#060;/span&#062;&#060;/TD&#062;<BR> &#060;TD bgcolor="&#060;%=bgcolor%&#062;" align="center"&#062;&#060;span class="calendar"&#062;<BR> &#060;%=DayOf%&#062;<BR> &#060;/span&#062;&#060;/TD&#062;<BR> &#060;TD bgcolor="&#060;%=bgcolor%&#062;" align="center"&#062;&#060;span class="calendar"&#062;<BR> &#060;%=DayOf%&#062;<BR> &#060;/span&#062;&#060;/TD&#062;<BR> &#060;TD bgcolor="&#060;%=bgcolor%&#062;" align="center"&#062;&#060;span class="calendar"&#062;<BR> &#060;%=DayOf%&#062;<BR> &#060;/span&#062;&#060;/TD&#062;<BR> &#060;TD bgcolor="&#060;%=bgcolor%&#062;" align="center"&#062;&#060;span class="calendar"&#062;<BR> &#060;%=DayOf%&#062;<BR> &#060;/span&#062;&#060;/TD&#062;<BR> &#060;/TR&#062;<BR> &#060;% Next %&#062;<BR>&#060;/table&#062;<BR>&#060;/div&#062;<BR><BR>

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

## It would be easier to rewrite it..

Let&#039;s see...off top of my head...untested:<BR><BR><BR>&#060;TABLE Border=1&#062;<BR> &#060;TR&#062;<BR>&#060;% For d = 1 To 7 %&#062;<BR> &#060;TH&#062;&#060;%=WeekdayName(d)%&#062;&#06 0;/TH&#062;<BR>&#060;% Next %&#062;<BR> &#060;/TR&#062;<BR>&#060;%<BR>CYear = Request("Year") &#039; 1601 to 2399<BR>CMonth = Request("Month") &#039; 1 to 12<BR>first = DateSerial( CYear, Cmonth, 1 )<BR>last = DateSerial( CYear, Cmonth+1, 0 )<BR><BR>startat = first - WeekDay(first) + 1<BR>endat = last - WeekDay(last) + 7<BR><BR>For w = startat To endat Step 7<BR> Response.Write "&#060;TR&#062;" & vbNewline<BR> For d = w To w+6<BR> If d &#060; first OR d &#062; last Then <BR> Response.Write "&#060;TD&#062;&amp;nbsp;&#060;/TD&#062;"<BR> Else <BR> Response.Write "&#060;TD&#062;" & Day(d) & "&#060;/TD&#062;"<BR> End If<BR> Next<BR> Response.Write "&#060;/TR&#062;" & vbNewline<BR>Next<BR>%&#062;<BR>&#060;/TABLE&#062;<BR><BR> <BR>

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

## Yep, that worked.

After I posted it, I tried it.<BR><BR>Call it via something like:<BR><BR>http://localhost/DearAbby/quickCalendar.asp?Year=2003&Month=11<BR><BR>Trivia l to clean it up a bit. For example:<BR> &#060;TABLE Width="80%" Border=1 CellPadding=5&#062;<BR>and<BR> &#060;TH width="14%"&#062;&#060;%=Weekday(d)%&#062;&#060;/TH&#062;<BR><BR>Wasn&#039;t that a crappy program you found? Amazing.<BR><BR><BR>

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

## Here, prettied up a bit...

&#060;HTML&#062;&#060;BODY&#062;<BR>&#060;CENTER&# 062;<BR>&#060;TABLE Width="80%" Border=1 CellPadding=5&#062;<BR> &#060;TR&#062; <BR>&#060;% For d = 1 To 7 %&#062; <BR> &#060;TH width="14%"&#062;&#060;%=WeekdayName(d)%&#062;&#06 0;/TH&#062; <BR>&#060;% Next %&#062; <BR> &#060;/TR&#062; <BR>&#060;% <BR>CYear = Request("Year") &#039; 1601 to 2399 <BR>CMonth = Request("Month") &#039; 1 to 12 <BR>first = DateSerial( CYear, Cmonth, 1 ) <BR>last = DateSerial( CYear, Cmonth+1, 0 ) <BR><BR>startat = first - WeekDay(first) + 1 <BR>endat = last - WeekDay(last) + 7 <BR><BR>For w = startat To endat Step 7 <BR> Response.Write "&#060;TR&#062;" & vbNewline <BR> For d = w To w+6 <BR> If d &#060; first OR d &#062; last Then <BR> Response.Write "&#060;TD bgColor=""lightgrey""&#062;&amp;nbsp;&#060;/TD&#062;" <BR> Else <BR> If Weekday(d) = 1 OR Weekday(d) = 7 Then <BR> Response.Write "&#060;TD bgcolor=""lightblue"" Align=Center&#062;" & Day(d) & "&#060;/TD&#062;" <BR> Else<BR> Response.Write "&#060;TD bgcolor=""lightgreen"" Align=Center&#062;" & Day(d) & "&#060;/TD&#062;"<BR> End If <BR> End If <BR> Next <BR> Response.Write "&#060;/TR&#062;" & vbNewline <BR>Next <BR>%&#062; <BR>&#060;/TABLE&#062; <BR>&#060;/CENTER&#062;<BR>&#060;/BODY&#062;&#060;/HTML&#062;<BR>

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

## Last version for tonight

&#060;HTML&#062;&#060;BODY&#062;<BR>&#060;CENTER&# 062;<BR>&#060;TABLE Width="80%" Border=1 CellPadding=5&#062;<BR> &#060;TR&#062; <BR>&#060;% For d = 1 To 7 %&#062; <BR> &#060;TH width="14%"&#062;&#060;%=WeekdayName(d)%&#062;&#06 0;/TH&#062; <BR>&#060;% Next %&#062; <BR> &#060;/TR&#062; <BR>&#060;% <BR>CYear = Request("Year") &#039; 1601 to 2399 <BR>CMonth = Request("Month") &#039; 1 to 12 <BR>first = DateSerial( CYear, Cmonth, 1 ) <BR>last = DateSerial( CYear, Cmonth+1, 0 ) <BR><BR>startat = first - WeekDay(first) + 1 <BR>endat = last - WeekDay(last) + 7 <BR><BR>For w = startat To endat Step 7 <BR> Response.Write "&#060;TR&#062;" & vbNewline <BR> For d = w To w+6 <BR> val = Day(d)<BR> If d &#060; first OR d &#062; last Then <BR> bg = "lightgrey" : val = "&amp;nbsp;"<BR> Elseif Weekday(d) = 1 OR Weekday(d) = 7 Then <BR> bg = "lightblue"<BR> Else<BR> bg = "lightgreen"<BR> End If<BR>%&#062;<BR> &#060;TD bgcolor="&#060;%=bg%&#062;"&#062;&#060;%=val%&#062 ;&#060;/TD&#062;<BR>&#060;%<BR> Next <BR> Response.Write "&#060;/TR&#062;" & vbNewline <BR>Next <BR>%&#062; <BR>&#060;/TABLE&#062; <BR>&#060;/CENTER&#062;<BR>&#060;/BODY&#062;&#060;/HTML&#062;<BR>

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

## But if you want a little popup calendar...

http://www.ClearviewDesign.com/Newbie<BR><BR>One that I created about 4 or 5 years ago so it should work in *all* browsers. <BR><BR>

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

## Okay, I fibbed a little

If you need a narrow calendar, then just change the top of it:<BR><BR>&#060;TABLE Width="300" Border=1 CellPadding=5&#062;<BR> &#060;TR&#062; <BR>&#060;% For d = 1 To 7 %&#062; <BR> &#060;TH width="14%" align="center"&#062;&#060;%=WeekdayName(d, True)%&#062;&#060;/TH&#062; <BR>&#060;% Next %&#062; <BR> &#060;/TR&#062; <BR>************<BR><BR>The "TRUE" in WeekdayName asks to use a 3 letter abbreviation for the name.<BR>You can also add in <BR> align="center"<BR>for the &#060;TD&#062; as you wish.<BR><BR>

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

## RE: Last version for tonight

Thanks Bill!<BR><BR> But, for some reason, my code made each month a day off and now with your code it&#039;s TWO DAYS OFF! <BR><BR> I&#039;m not sure what&#039;s going on. ???

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

## It's working perfectly for me

When I do this:<BR> http://localhost/DearAbby/quickCalendar.asp?Year=2003&Month=12<BR><BR>I get a calendar for December, 2003, that starts with the first of the month on Monday, and that is *CORRECT*.<BR><BR>http://localhost/DearAbby/quickCalendar.asp?Year=2004&Month=1<BR><BR>Shows January, 2004, with first of month on Thursday.<BR><BR>Etc.<BR><BR>Wait! I&#039;ll try an exotic one:<BR><BR>http://localhost/DearAbby/quickCalendar.asp?Year=1941&Month=12<BR><BR>Decemb er 7, 1941, is indeed on a Sunday. As any student of history knows.<BR><BR>So either you are looking at the wrong calendar or somehow something is really screwed up.<BR><BR>OH! Wait! What country are you in?<BR><BR>In your country, what is the *USUAL* first day of the week?<BR><BR>

10. Senior Member
Join Date
Dec 1969
Posts
2,768

## Paging through the months

I think the problem may be with paging through the months. With your code, I can&#039;t do it and when I added it to my code it made the date two-days off. Mine was one-day off so it&#039;s definitely my code - I think it&#039;s the paging.<BR><BR>Anyone recommend a good calendar to page through the months correctly?

#### Posting Permissions

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