Solved

Free calender code

Posted on 2002-05-29
9
1,472 Views
Last Modified: 2012-08-13
Do anyone have the free code of calender in ASP?
0
Comment
Question by:lemontree
9 Comments
 
LVL 33

Expert Comment

by:hongjun
ID: 7043747
Go to www.aspin.com
Search for calendar.
Lots there.

hongjun
0
 
LVL 33

Expert Comment

by:hongjun
ID: 7043753
This is a good one
http://www.leonamarant.com/resources/

hongjun
0
 
LVL 33

Accepted Solution

by:
hongjun earned 50 total points
ID: 7043758
The above link seems not to load. Post the code here.


calendar.asp
============
<!--#INCLUDE FILE="functions_holiday.asp"-->
<%
Response.Expires = 0
Response.Buffer = true

'------CALENDAR VARIABLES-------------------------------------------------
dayWidth = "45"                              'width of each day block
dayHeight = "40"                        'height of each day block
fontface = "verdana"                  'font face used in calendar

mainColor = "#003399"                  'background color of calendar
secondColor = "lightgrey"            'background color of day blocks in calendar
monthNameColor = "black"            'color of month text at top of calendar
weekdayNameColor = "white"            'color of weekday/holiday text in day blocks
showHolidays = true                        'whether or not to show holidays
showNonMonthDays = true                  'whether or not to display days not in selected month
calendarBorder = "#FFFFFF"            'color of the calendar's border

'***IMPORTANT NOTE***
'If you decide to include this calendar on another page (or rename this page),
'be sure to change the variable below to point to that page. This calendar is
'designed to work using querystrings (to pass in month and year variables). If
'the page this calendar is on requires any other querystring variables, you must
'specify them as well (see below).

calendarLink = "calendar.asp"
'eg:
'  calendarLink = "myPage.asp"

'If your page includes other querystring variables, you must specify them in the
'string below. Seperate each variable with a comma.

strQstring = ""
'eg:
'  strQstring = "myVar1,myVar2,myVar3"

'***EXAMPLE***
'If the page this calendar is being included on index.asp and the page uses other
'querystring values (see below):
'
'  index.asp?isCalendar=yes&variable1=x&variable2=z
'
'then you must do the following for the calendar to function properly
'  
'  calendarLink = "index.asp"
'  strQstring = "isCalendar,variable1,variable2"
'


'-------------------------------------------------------------------------
'----------------YOU DO NOT NEED TO MODIFY THE CODE BELOW-----------------

calendarLink = calendarLink & "?"
if len(strQstring) > 0 then
      blnQstring = true
      qStringArray = split(strQstring,",")
      
      'append extra querystring vars to calendar link
      for qstrCnt = 0 to ubound(qStringArray)
            calendarLink = calendarLink & qStringArray(qstrCnt) & "=" & Request.QueryString(qStringArray(qstrCnt)) & "&"
      next
      
else
      blnQstring = false
end if

outerBorderColor       =      mainColor

IF Request("month") <> "" THEN
      theMonth = Request.QueryString("month")
ELSE
      theMonth = month(now)
END IF

IF Request("year") <> "" THEN
      theYear  = Request.QueryString("year")
ELSE
      theYear  = year(now)
END IF

IF Request("form")="y" THEN
      theMonth = Request("optMonth")
      theYear = Request("optYear")
END IF

theMonth = cInt(theMonth)
theYear = cInt(theYear)

'figure out month/year values for prev/next buttons

      prevMonth = theMonth - 1
      nextMonth = theMonth + 1
      prevYear = theYear
      nextYear = theYear

      IF theMonth = 1 THEN
            prevMonth = 12
            prevYear = theYear-1
      END IF

      IF theMonth = 12 THEN
            nextMonth = 1
            nextYear=theYear+1
      END IF

'figure out what day the month starts on
      myDate = theMonth & " 1, " & theYear
      myDay = weekDay(myDate)

'store num days in each month in an array
      monthArray = Array(0,31,28,31,30,31,30,31,31,30,31,30,31)
      daysInMonth = monthArray(theMonth)
      
'check to see if leap year
      IF theMonth = 2 THEN
            IF theYear MOD 400 = 0 THEN
                  daysInMonth = 29
            END IF
            
            IF theYear MOD 4 = 0 AND NOT theYear MOD 100 = 0 THEN
                  daysInMonth = 29
            END IF
      END IF

monthStartDate = cDate(theMonth & "/01/" & theYear)
monthEndDate   = cDate(theMonth & "/" & monthArray(theMonth) & "/" & theYear)

theStartDate = monthStartDate - myDay + 1

%>
<center>
<FORM name="myForm" method="GET" action="<%=calendarLink%>">
<font face="<%=fontface%>" size="-1" color="<%=monthNameColor%>"><b><%=monthname(theMonth)%>,&nbsp;<%=theYear%></b></font>
<TABLE bgcolor="<%=calendarBorder%>" cellpadding="1" cellspacing="0" border="0">
<INPUT TYPE="hidden" name="form" value="y">
<%if blnQstring = true then%>
      <%for qstrCnt = 0 to ubound(qStringArray)%>
            <INPUT TYPE="hidden" name="<%=qStringArray(qstrCnt)%>" value="<%=Request.QueryString(qStringArray(qstrCnt))%>">
      <%next%>
<%end if%>

<TR><TD colspan=2>
<TABLE bgcolor="<%=outerbordercolor%>" cellspacing="1" cellpadding="1" border="0">
<TR><TD>
      <TABLE cellspacing="1" cellpadding="1" border="0">

                  
      <TR>
            <%FOR dayName = 1 to 7%>
            <TD align="center">
                  <font face="<%=fontface%>" size="-2" color="<%=weekdayNameColor%>">
                        <B><%=left(weekdayname(dayName),3)%></B>
                  </font>
                  </font>
            </TD>            
            <%NEXT%>
      </TR>
                                                                                                      <!------CREATE CALENDAR GRID------>

      <TR>
      <%
      rowCount = 1
      FOR x = 0 to 41
            colCount = colCount + 1
            aDate = theStartDate + x
                  
            'set up days in month
            IF month(aDate) = theMonth THEN
                  isMo = TRUE
            ELSE
                  isMo = FALSE
            END IF
            
            'determine bgcolor and font color of day
            IF NOT isMo THEN
                  bColor = mainColor
            ELSE
                  bColor = secondColor
            END IF
            
            IF isMo THEN
                  selColor = mainColor
            ELSE
                  selColor = secondColor
            END IF
            
            'determine whether or not to display the day
            IF showNonMonthDays then
                  showDay = true
            ELSE
                  IF isMo then
                        showDay = true
                  ELSE
                        showDay = false
                  END IF
            END IF
            
            %>
            
            <TD width="<%=dayWidth%>" height="<%=dayHeight%>" align="center" valign="top" bgcolor="<%=bColor%>">
                  <font color="<%=selColor%>" face="<%=fontface%>" size="-1">
                  <%IF showDay THEN%>
                        <%IF aDate > now THEN%>
                              <font color="<%=selColor%>" face="<%=fontface%>" size="-1"><%=day(aDate)%></font>
                        <%ELSE%>
                              <%=day(aDate)%>
                        <%END IF%>
                  
                        <%if showHolidays then%>
                              <br />
                              <%if isHoliday(aDate) then%>
                                    <font size="-2" face="<%=fontface%>"><%=holidayName(aDate)%></font>
                              <%else%>
                              <%end if%>
                        <%end if%>
                  <%END IF%>
                  </font>
            </TD>
            
            <%
            IF colCount = 7 AND x <> 41 THEN                              'end row division and begin new%>
                  </TR>
                  <TR>
                  <%
                  colCount = 0
                  IF x <> daysInMonth + myDay - 1THEN
                        rowCount = rowCount + 1
                  END IF
            END IF
      NEXT
      'call close_DB()
      %>
      </TR>
      
      </TABLE>
</TD></TR>
</TABLE>
</TD></TR>
<TR>
<TD align="left" valign="bottom">
      <select name="optMonth" style="font-size:10px;font-family=<%=fontFace%>;">
            <%FOR monthX = 1 to 12%>
                  <OPTION VALUE=<%=monthX%><%IF cint(monthX)=cint(theMonth) THEN%> selected<%END IF%>><%=monthName(monthX,3)%></OPTION>
            <%NEXT%>
      </select>
      <select name="optYear" style="font-size:10px;font-family=<%=fontFace%>;">
            <%FOR yearX = theYear - 2 to year(now) + 5%>
                  <OPTION VALUE=<%=yearX%><%IF cint(yearX)=cint(theYear) THEN%> selected<%END IF%>><%=yearX%></OPTION>
            <%NEXT%>
      </select>
      <a title="GO" href="javascript: myForm.submit()"><font face="<%=fontface%>" size="-2">go</font></a>
</TD>
<TD align="right" valign="bottom">
      <a href="<%=calendarLink%>month=<%=prevMonth%>&year=<%=prevYear%>" title="prev"><font face="<%=fontface%>" size="-2"><</font></a>&nbsp;
      <a href="<%=calendarLink%>month=<%=nextMonth%>&year=<%=nextYear%>" title="next"><font face="<%=fontface%>" size="-2">></font></a>&nbsp;
</TD>
</TR>
</TABLE>
</FORM>
</center>

<!-- PLEASE DO NOT REMOVE THE COMMENT BELOW -->
<!-- ASP Calendar created by Leon Amarant -->
<!-- source code can be found at http://www.leonamarant.com/resources/ -->




functions_holiday.asp
=====================
<%
'--------------------------HOLIDAY FUNCTIONS-------------------------------------
'this file contains functions to be used with ASPCalendar
'should be self explanatory - only included the major holidays

function isHoliday(theDate)
      isHoliday = False
      'check New Years Day (1/1/xxxx)
      IF isNewYears(theDate)_
       OR isMemorialDay(theDate)_
       OR isIndependenceDay(theDate)_
       OR isLaborDay(theDate)_
       OR isThanksgiving(theDate)_
       OR isDayAfterThanksgiving(theDate)_
       OR isChristmas(theDate) THEN
            isHoliday = TRUE
      END IF
end function

function holidayName(theDate)
      holidayName = ""
      IF isNewYears(theDate) THEN
            holidayName = "New Yrs Day"
      ELSEIF isMemorialDay(theDate) THEN
            holidayName = "Memrl Day"
      ELSEIF isIndependenceDay(theDate) THEN
            holidayName = "4th of July"
      ELSEIF isLaborDay(theDate) THEN
            holidayName = "Labor Day"
      ELSEIF isThanksgiving(theDate) THEN
            holidayName = "Turkey Day"
      'ELSEIF isDayAfterThanksgiving(theDate) THEN
            'holidayName = "Day After Turkey Day"
      ELSEIF isChristmas(theDate) THEN
            holidayName = "X-Mas"      
      END IF
end function

function firstMonday(theDate)
      m = month(theDate)
      y = year(theDate)
      fDay = dateSerial(y,m,1)
      for n = fDay to fDay + 6
            if N Mod 7 = vbMonday then exit for
      next
      firstMonday = int(N)
end function

function fourthThursday(theDate)
      m = month(theDate)
      y = year(theDate)
      fDay = dateSerial(y,m,1)
      for n = fDay to fDay + 6
            if N Mod 7 = vbThursday then
                  fThurs = n
                  exit for
            end if
      next

      for p = fThurs to cdate(m & "/30/" & y)
            if p mod 7 = vbThursday then
                  thursCount = thursCount + 1
            end if
            if thursCount = 4 then
                  fourthThursday = p
                  exit for
            end if
      next
end function

function isNewYears(theDate)      
      '(1/1/xxxx)
      if month(theDate) = 1 and day(theDate) = 1 then
            'date is New Years Day
            isNewYears = TRUE
      end if
end function

function isMemorialDay(theDate)      
      '(last Monday of May)
      if month(theDate) = 5 then
            dy = firstMonday(theDate) + (4*7)
            if month(dy) <> 5 then
                  dy = dy - 7
            end if
            if theDate = dy then
                  isMemorialDay = true
            end if
      end if
end function

function isIndependenceDay(theDate)      
      '(7/4/xxxx)
      if month(theDate) = 7 and day(theDate) = 4 then
            'date is New Independence Day
            isIndependenceDay = TRUE
      end if
end function

function isLaborDay(theDate)      '(first monday of september)
      if month(theDate) = 9 and theDate = firstMonday(theDate) then
            'date is Labor Day
            isLaborDay = TRUE
      end if
end function

function isThanksgiving(theDate)      '(fourth Thursday of November)
      if month(theDate) = 11 then
            if theDate = fourthThursday(theDate) then
                  'it's Turkey Day! (or the day after)
                  isThanksgiving = TRUE
            end if      
      end if
end function

function isDayAfterThanksgiving(theDate)      '(day after the fourth Thursday of November)
      if month(theDate) = 11 then
            if theDate = fourthThursday(theDate - 1) + 1 then
                  'it's the day after Turkey Day
                  isDayAfterThanksgiving = TRUE
            end if      
      end if
end function

function isChristmas(theDate)      '(12/25/xxxx)
      if month(theDate) = 12 and day(theDate) = 25 then
            'date is X-Mas
            isChristmas = TRUE
      end if
end function


'PLEASE DO NOT REMOVE THE COMMENT BELOW
'-created by Leon Amarant http://www.leonamarant.com
%>


hongjun
0
 
LVL 33

Expert Comment

by:hongjun
ID: 7043760
Modify the functions_holiday.asp file to suit to your own country. Different country has different public holidays.

hongjun
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Expert Comment

by:chops123
ID: 7043762
lemontree... why use ASP,use this javascript

Save the code below into a .js file and use the file wherever required

USAGE:
<script type="text/javascript" src="/calender.js"></script>
<form method="POST" action="--WEBBOT-SELF--">
  <input type="text" onClick="popupCalender('myDate')"  name="myDate" size="20"></p>
</form>

<<calendar.js>>
-------------------------------------------------------
var frmField, frmValue,aMonth;
var minYear = 1940, maxYear = 2005;

document.write('<table id="tblCalender" cellpadding="1" cellspacing="1" border="0"'
      +'style="position:absolute;visibility:hidden;font-family:sans-serif;font-size:8pt;font-weight:bold;border:thin solid #000;background-color:#ccc;">');
document.write('<tr>');
document.write('<td colspan="6" align="center">');

document.write('<select name="optCalenderMonth" onchange="updateMenu();" style="font-size:8pt;font-weight:bold;">');
for (i=0; i<12; i++){
      document.write('<option value="' + i + '">' + getMonths(i) + '</option>');
}
document.write('</select>&nbsp;&nbsp;');

document.write('<select name="optCalenderYear" onchange="updateMenu();" style="font-size:8pt;font-weight:bold;">');
for (i=minYear; i<=maxYear; i++){
      document.write('<option value="' + i + '">' + i + '</option>');
}
document.write('</select>');
document.write('</td>');

document.write('<td align="right" valign="top"><span style="cursor:hand;font-size:8px;text-align:center;" '
      + 'onmouseover="closeOver();" '
      + 'onmouseout="closeOut();" '
      + 'onclick="closeClick();">&nbsp;X&nbsp;</span></td>');
document.write('</tr>');

document.write('<tr>');
var str = "Sun,Mon,Tue,Wed,Thu,Fri,Sat";
var arr = str.split(',');
for (i=0; i<7; i++){
      document.write('<th style="background-color:#fff;">' + arr[i] + '</th>');
}
document.write('</tr>');
// Grid
for (i = 0; i < 6; i++) { // 6 weeks
      document.write('<tr>');
      for (j = 0; j < 7; j++) { // 7 days per week
            document.write('<td id="tdCalender" style="text-align:left;vertical-align:top;width:25px;cursor:hand;background-color:#fff;" '
                  + 'onmouseover="calOver();" '
                  + 'onmouseout="calOut();" '
                  + 'onclick="calClick();">');
            document.write('</td>');
      }
      document.write('</tr>');
}
document.write('</table>');


function getDates(y, m) {
      var dates = new Array(42);
      var first = new Date(y, m, 1).getDay();
      var days = 32 - new Date(y, m, 32).getDate();
      var i = 1;
      for (j = first; j <first+days; j++) {
            dates[j] = i;
            i++;
      }
      return dates;
}
function getMonths(i){
      var sMonths = "January,February,March,April,May,June,July,August,September,October,November,December";
      aMonth = sMonths.split(',');
      return aMonth[i];
}
function updateMenu(){
      updateCalender(document.getElementById('optCalenderYear').value, document.getElementById('optCalenderMonth').value);
}
function updateCalender(y, m) {
      var arr = getDates(y, m);
      for (i=0; i<document.getElementById('optCalenderYear').options.length; i++) {
            if (document.getElementById('optCalenderYear').options[i].value == y) {
                  document.getElementById('optCalenderYear').options.selectedIndex = i;
            }
      }
      for (i=0; i<document.getElementById('optCalenderMonth').options.length; i++) {
            if (document.getElementById('optCalenderMonth').options[i].value == m) {
                  document.getElementById('optCalenderMonth').options.selectedIndex = i;
            }
      }
      for (i=0; i<arr.length; i++) {
            if (!isNaN(arr[i])) tdCalender[i].innerText = arr[i];
            else tdCalender[i].innerText = "";
      }
}
function popupCalender(field){
      
//      alert(field)
frmField = document.getElementById(field);
      frmValue = frmField.value;
      var thisDate, thisYear, thisMonth;
      with (document.getElementById('tblCalender')){
            style.visibility = "visible";
            style.top = document.body.scrollTop + event.clientY - 10;
            style.left = document.body.scrollLeft + event.clientX + 6;
//            style.top = field.style.top-10;
//            style.left = field.style.left + 6;

      }
      var reDate = /^\d{2}\/\d{2}\/\d{4}$/;
      if (reDate.test(frmValue)) {
            thisDate = frmValue.split('/');
            thisYear = thisDate[2];
            thisMonth = thisDate[0]-1;
      }
      else {
            thisDate = new Date();
            thisYear = thisDate.getFullYear();
            thisMonth = thisDate.getMonth();
      }
      document.all.optCalenderMonth.focus();
      updateCalender(thisYear, thisMonth);
}
function calOver() {
      if (!isNaN(parseInt(event.srcElement.innerText))) {
            event.srcElement.style.color = "#f00";
      }
}
function calOut() {
      if (!isNaN(parseInt(event.srcElement.innerText))) {
            event.srcElement.style.color = "#000";
      }
}
function calClick() {
      if (!isNaN(parseInt(event.srcElement.innerText))) {
            var strDate = "";
            var strMonth = parseInt(document.getElementById('optCalenderMonth').options[document.getElementById('optCalenderMonth').selectedIndex].value);
            var strYear = document.getElementById('optCalenderYear').options[document.getElementById('optCalenderYear').selectedIndex].value.substring(2,4);
            if (parseInt(event.srcElement.innerText) < 10) strDate += "0";
            strDate += event.srcElement.innerText + '-' + aMonth[strMonth].substring(0,3) + '-';
            strDate += strYear;
            frmField.value = strDate;
            document.getElementById('tblCalender').style.visibility = "hidden";
      }
}
function closeOver() {
      event.srcElement.style.backgroundColor = "#006";
      event.srcElement.style.color = "#fff";
}
function closeOut() {
      event.srcElement.style.backgroundColor = "#ccc";
      event.srcElement.style.color = "#000";
}
function closeClick() {
      frmField.value = frmValue;
      document.getElementById('tblCalender').style.visibility = "hidden";
}
-----------------------------------------------------------

Rgds
KC
0
 
LVL 1

Expert Comment

by:procyn00
ID: 7044515
Just wanted to point out as well... if you have asp.net available making a calendar is a simple as.

<asp:calendar runat="server" />

A very good example of a calendar that allows you to add events is located here. http://asp-dev.com/download.asp
0
 
LVL 33

Expert Comment

by:hongjun
ID: 7048703
you there?

hongjun
0
 

Author Comment

by:lemontree
ID: 7050451
Hello hongjun,
      I am here but I still trying some functions about it, I will reply u later.
      Thanks a lot.
0
 

Author Comment

by:lemontree
ID: 7050456
However, I want to ask one question to all:
For ASP and JS, which one is better for writing the calender?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
two-way Authentication ASP 3 80
Out the count variables 6 53
Age between date range query (SP) 13 52
Hide row when retrieving data from database 6 53
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now