Microsoft KB Archive/245566

= How to Create a Perpetual Calendar Using Active Server Pages =

Article ID: 245566

Article Last Modified on 8/8/2007

-

APPLIES TO


 * Microsoft Internet Information Services 5.0

-



This article was previously published under Q245566



SUMMARY
This article demonstrates how to create a Web page calendar that will not easily go out of date using Microsoft Active Server Pages (ASP).



MORE INFORMATION
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. Save the following code to your Web site as "Calendar.asp" in a folder that has at least "script" access defined. When the page is browsed, it will display a calendar with menu buttons that will allow a Web client to choose to display the next or previous month's calendar. <% @Language="vbscript" %> <% ' force declaration of all variables Option Explicit Dim intYear, intMonth, intDay Dim intNumberOfDays, strDaysInMonths Dim strDate, strMonthName Dim strStyle, strTitle Dim strMethod, strURL Dim strFirstDay, strLastDay, strCurrentDay Dim dtmPrev, dtmNext Dim X,Y,Z ' find out the URL of the page and the HTTP method used strMethod = UCase(Request.ServerVariables("REQUEST_METHOD")) strURL = LCase(Request.ServerVariables("URL")) ' if it's a GET then it's a regular browser request If strMethod="GET" Then ' use today's date intDay  = CInt(Day(Date)) intMonth = CInt(Month(Date)) intYear = CInt(Year(Date)) strFirstDay = CStr(intMonth) & "-1-" & CStr(intYear) strDate = CStr(intMonth) & "-" & CStr(intDay) & "-" & CStr(intYear) ' if it's a POST then it's a specific request Else ' get the submitted date intDay  = CInt(Day(Date)) intMonth = CInt(Request.Form("txtMonth")) intYear = CInt(Request.Form("txtYear")) strFirstDay = CStr(intMonth) & "-1-" & CStr(intYear) strDate    = strFirstDay End If ' is a date in a leap year? Function IsLeapYearDate(dtmTestDate) IsLeapYearDate = False If IsDate(dtmTestDate) Then Dim dtmTempDate dtmTempDate = "1/31/" & Year(dtmTestDate) dtmTempDate = DateAdd("m", 1, dtmTempDate) If Day(dtmTempDate) = 29 Then IsLeapYearDate = True End If End Function

' create string of days in months If IsLeapYearDate("1/1/" & intYear) Then strDaysInMonths = "312931303130313130313031" Else strDaysInMonths = "312831303130313130313031" End If ' get some date stuff strMonthName   = CStr(MonthName(intMonth)) intNumberOfDays = CInt(Mid(strDaysInMonths,((intMonth-1)*2)+1,2)) strLastDay     = CStr(intMonth) & "-" & intNumberOfDays & "-" & CStr(intYear) ' build the page title strTitle = "Calendar for " & strMonthName & " " & intYear

' get the next and previous months for the menus dtmPrev = CDate(DateAdd("m", -1, strDate)) dtmNext = CDate(DateAdd("m", 1, strDate)) %> <%=strTitle%>

<%=strTitle%>

Note that this ASP code could be modified to perform various functions, such as:
 * Display common daily events for a department
 * List the hours that a store is open
 * Integrate calendar events kept in a database

For more information on Microsoft scripting technologies, please see the Microsoft Developer Network (MSDN) Web site:

http://msdn2.microsoft.com/en-us/library/ms950396.aspx

Keywords: kbcodesnippet kbhowto kbscript KB245566

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.