Solved

Calendar Missing Dates???

Posted on 2004-08-24
5
217 Views
Last Modified: 2012-05-05
I have been developing a calendar for the past while and sad to say this is not my first time back on EE looking for help, to date I have managed to get most of it working but here is my current problem.

The calendar is designed to inform users of business closing dates (bank holiday & special occasions)  

Here is a list of the dates for the current year and 2005, which are in a access table

    Start Date      |      End Date      |     Type      |

   02/08/2004           02/08/2004         Holiday
   25/10/2004           25/10/2004         Holiday
   25/12/2004           02/01/2005         Occasion
   03/01/2005           03/01/2005         Holiday
   17/03/2005           17/03/2005         Holiday
   25/03/2005           25/03/2005         Holiday
   28/03/2005           28/03/2005         Holiday
   02/05/2005           02/05/2005         Holiday
   06/06/2005           06/06/2005         Holiday
   01/08/2005           01/08/2005         Holiday
   31/10/2005           31/10/2005         Holiday
   24/12/2005           02/01/2006         Occasion


** Problem **

the loop which I am currently running misses a few dates, they are

01/01/2005 and 02/01/2005  
17/03/2005
25/03/3005

I have tried everything to get them working but I cant, i have included the main code below

=============================================================

<!-- #include file="../inc/connection.asp" -->
<!--#include virtual="../inc/adovbs.inc"-->
<%
Session.lcid = 2057

' GET ALL INFO NEEDED
Dim dtToday, dateToday, strMonth, strMonthB, strMonthName, strYear, iFirstDayOfMonth, iDaysInMonth
Dim dFirstDay, dLastDay, strPrevMonth, strNextMonth
Dim aCalendarDays(42)            
Dim iColumns, iRows      , iDay, iWeek
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~      
IF Request.QueryString("CD") <> "" Then
      dateToday = Request.QueryString("CD")
Else
    dateToday = formatdatetime(Date(), vbShortDate)      ' get todays date
End If

strMonth = Month(dateToday)                                          ' get month number   1 -12
strMonthName = MonthName(strMonth)                           ' get month name   Jan - Dec
strYear = Year(dateToday)                                          ' get year   2004 - ______

IF strMonth = 1 THEN                                                ' convert 1 to 01 etc
      strMonthB = 0 & strMonth
ELSEIF strMonth = 2 THEN
      strMonthB = 0 & strMonth
ELSEIF strMonth = 3 THEN
      strMonthB = 0 & strMonth
ELSEIF strMonth = 4 THEN
      strMonthB = 0 & strMonth
ELSEIF strMonth = 5 THEN
      strMonthB = 0 & strMonth
ELSEIF strMonth = 6 THEN
      strMonthB = 0 & strMonth
ELSEIF strMonth = 7 THEN
      strMonthB = 0 & strMonth
ELSEIF strMonth = 8 THEN
      strMonthB = 0 & strMonth
ELSEIF strMonth = 9 THEN
      strMonthB = 0 & strMonth
ELSE
      strMonthB = strMonth
END IF

' FIRST DAY of the MONTH
iFirstDayOfMonth = DatePart("w", DateSerial(Year(dateToday), Month(dateToday), 1))
' NUMBER of DAYS in the MONTH
iDaysInMonth = DatePart("d", DateSerial(Year(dateToday), Month(dateToday)+1, 1-1))

dFirstDay = "01/" & strMonthB & "/" & strYear                              ' get FIRST DAY of the current month
dLastDay = iDaysInMonth & "/" & strMonthB & "/" & strYear            ' get LAST DAY of the current month
strPrevMonth = DateAdd("m", -1, dateToday)                                    ' get PREVIOUS month
strNextMonth = DateAdd("m",  1, dateToday)                                     ' get NEXT month
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
For counter = 1 to iDaysInMonth
    aCalendarDays(counter + iFirstDayOfMonth - 1) = counter
Next

iColumns = 7
iRows    = 6 - Int((42 - (iFirstDayOfMonth + iDaysInMonth)) / 7)
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<TITLE> - </TITLE>
<META http-equiv="Content-Type" CONTENT="text/html; charset=iso-8859-1" >
<META NAME="description" CONTENT="" >
<META NAME="keywords" CONTENT="" >
<META NAME="robots" CONTENT="index,follow" >
<LINK HREF="../inc/style.css" REL="stylesheet" TYPE="text/css" >
<script src="../inc/interactive.js" type="text/javascript"></script>
</HEAD>
<BODY>
<br>
Todays Date:  <%=(dateToday)%><br>
Month:  <%=(strMonth)%><br>
Month Name:  <%=(strMonthName)%><br>
Year:  <%=(strYear)%><br>
First Day:  <%=(iFirstDayOfMonth)%><br>
Number of days in month:  <%=(iDaysInMonth)%><br>
First Day of Month:  <%=(dFirstDay)%><br>
Last Day of Month:  <%=(dLastDay)%><br>
<br>
Previous Month:   <%=(strPrevMonth)%><br>
Next Month:   <%=(strNextMonth)%><br>
<br>
<br>
<!-- START CALENDAR TABLE -->
<table width="245" border="0" align="center" cellpadding="0" cellspacing="0" class="CC_BORDER">
<tr><td width="13" height="15" align="center" valign="middle"><img src="../images/icon_calendar.gif" width="11" height="11"></td><td width="219" height="15" class="POP_HEAD">&nbsp;Announcement Calendar</td><td width="13" height="15">&nbsp;</td></tr>
<tr><td colspan="3"><img src="../images/breaker.gif" width="245" height="1"></td></tr>
<tr><td width="13">&nbsp;</td><td>&nbsp;</td><td width="13">&nbsp;</td></tr>
<tr><td width="13">&nbsp;</td><td valign="top">
<!-- START Editable Region -->
<table width="219" border="0" cellpadding="0" cellspacing="1" >
<tr><td width="29" class="CALENDAR_DAYS"><A HREF="test.asp?CD=<%= strPrevMonth %>">&laquo;</a></td><td colspan="5" class="CALENDAR_MONTH"><%= MonthName(Month(dateToday)) & " - " & Year(dateToday) %></td><td width="29" class="CALENDAR_DAYS"><A HREF="test.asp?CD=<%= strNextMonth %>">&raquo;</a></td></tr>
<tr class="CALENDAR_DAYS">
      <% For iDay = vbSunday To vbSaturday %>
            <td width="29"><%= WeekDayName(iDay, True) %>.</td>
    <% Next %>
</tr>
<%
For iWeek = 1 To iRows
               Response.Write "<tr valign='top' class='PLAIN'>"
          For iDay = 1 To iColumns
                        ' Checks to see if there is a day this month on the date being written
                        
                        If aCalendarDays((iWeek-1)*7 + iDay) > 0 THEN
                                dtOnDay = DateSerial(Year(dateToday), Month(dateToday), aCalendarDays((iWeek-1)*7 + iDay))

' define what type of event it is
strHol = "Holiday"
strOcc = "Occasion"
TodayDate = Date()
' set up database connection & sql
Set objRS = Server.CreateObject("ADODB.RecordSet")

strSQL = "SELECT CalDateFrom, CalDateTo, CalType FROM tblCalendar WHERE ((CalDateFrom >= #" & dFirstDay & "# AND CalDateTo <= #" & dLastDay & "#) " & _
"OR (CalDateFrom < #" & dFirstDay & "# AND CalDateTo >= #" & dFirstDay & "# AND CalDateTo <= #" & dLastDay & "#) " & _
"OR (CalDateFrom <= #" & dLastDay & "# AND CalDateFrom >= #" & dFirstDay & "# AND CalDateTo > #" & dLastDay & "#) " & _
"OR (CalDateFrom < #" & dFirstDay & "# AND CalDateTo > #" & dLastDay & "#)) "

'Set objRS = objConnNNC.Execute(strSQL)
objRS.Open strSQL, objConnNNC, adOpenStatic, adLockReadOnly, adCmdText


' DO UNTIL NO RECORDS FOUND
If NOT objRS.BOF THEN

      objRS.MoveFirst
      
      DO UNTIL objRS.EOF
      
      IF dtOnDay = TodayDate THEN
      
                  IF dtOnDay = objRS("CalDateFrom") AND dtOnDay <= objRS("CalDateTo") AND objRS("CalType") = strHol THEN
                        strTAB =  "'CALENDER_CURRENT_HOL'"      
                  ELSEIF dtOnDay = objRS("CalDateFrom") AND dtOnDay <= objRS("CalDateTo") AND objRS("CalType") = strOcc THEN
                        strTAB =  "'CALENDER_CURRENT_OCC'"      
                  ELSE
                        strTAB =  "'CALENDER_CURRENT_BLA'"
                  END IF
                  
      ELSEIF dtOnDay >= objRS("CalDateFrom") AND dtOnDay <= objRS("CalDateTo") AND objRS("CalType") = strHol  THEN
            strTAB =  "'CALENDAR_Holiday'"      
      ELSEIF dtOnDay >= objRS("CalDateFrom") AND dtOnDay <= objRS("CalDateTo") AND objRS("CalType") = strOcc  THEN
            strTAB =  "'CALENDAR_Occasion'"      
      
            
      ELSE
            strTAB =  "'CALENDAR_BLANK'"      
      END IF

      objRS.MoveNext
      LOOP

ELSE

strTAB =  "'CALENDAR_BLANK'"

END IF



                        
                        Response.Write ("<TD CLASS=" & strTAB & ">&nbsp;<span class='CALENDAR_DATE'><a href='calendar.asp?CID=" & dtOnDay & "'>" & aCalendarDays((iWeek-1)*7 + iDay) & "</a></span><BR>&nbsp;")
                        Else
                          Response.Write ("<TD>&nbsp;")
                        End IF
                        
            Response.Write "</TD>"
            Next
            Response.Write "</TR>"
Next

objRS.Close
Set objRS = Nothing                        
%>
</table>
<!-- END Editable Region -->
<!-- START KEY -->
<table width="219" border="0" align="center" cellpadding="0" cellspacing="0">
<tr><td width="13">&nbsp;</td><td width="29">&nbsp;</td><td width="177">&nbsp;</td></tr>
<tr class="POP_HEAD"><td colspan="3">&nbsp;Calendar Key </td></tr>
<tr><td>&nbsp;</td><td width="29">&nbsp;</td><td>&nbsp;</td></tr>
<tr><td>&nbsp;</td><td width="29" class="CALENDAR_Holiday"><br><br></td>
<td valign="middle">&nbsp;&nbsp;Bank Holiday </td>
</tr>
<tr><td colspan="3"><img src="images/pixelborder_one.gif" width="1" height="1"></td></tr>
<tr><td>&nbsp;</td><td width="29" class="CALENDAR_Occasion"><br><br></td><td valign="middle">&nbsp;&nbsp;Special Occasion / Article </td></tr>
<tr><td colspan="3"><img src="images/pixelborder_one.gif" width="1" height="1"></td></tr>
<tr><td>&nbsp;</td><td width="29" class="CALENDER_CURRENT_BLANK"><br><br></td><td valign="middle">&nbsp;&nbsp;Current Date (<%=(formatdatetime(Date(), vbShortDate))%>) </td></tr>
</table>
<!-- END KEY -->
<tr><td width="13">&nbsp;</td><td>&nbsp;</td><td width="13"><img src="../images/callout_corner.gif" width="13" height="13" alt="Corner Border"></td></tr>
</table>
<!-- END CALENDAR TABLE -->
</body>
</html>


please please take a look at the code before i go mad :o(

Mark    
0
Comment
Question by:McSqueeb
5 Comments
 
LVL 31

Expert Comment

by:alorentz
ID: 11887874
Looks like may be a conversion problem with UK dates to Standard Dates.
0
 
LVL 22

Expert Comment

by:neeraj523
ID: 11889439
Helloo

It seems issue in your date format as mentioned by @Alorentz

Use following function to format date..

<%
Function formatDate(strDate)
      if isDate(strDate) Then
            strDate = Right("00" & Day(strDate),2) & "/" & _
            Left(MonthName(Month(strDate)),3) & "/" & Year(strDate)
      End if
            formatDate = strDate
End Function      
%>

format all the dates in your page with this funtcion..

neeraj523
0
 
LVL 1

Author Comment

by:McSqueeb
ID: 11890444
Nope that aint it,  

I have set the Session.lcid = 2057
I change the format of the dates  to dd/mm/yyyy
The dd/mm are set to 0 + date if less than 10    ie  2/9/2004 will turn into 02/09/2004

Im thinking its something to do with the loop itself, it picks up half the event then loses the rest... but i have tried everything I can think of and nothing is working.

Mark
0
 
LVL 1

Author Comment

by:McSqueeb
ID: 11890548
Thinking about it, i think i have figured the problem, it seems that the loop only picks out 1 date for each month,

eg:

 25/12/2004           02/01/2005         Occasion

 the calendar loops and creates december and colours the cells from the 25th to the 31st (picks it up as a single entry)

the calendar loops and creates january and SKIPS the end of the december event and picks up the holiday on the 3rd and colours it

the same thing happens in March where there are 3 events and the same again decemver 2005 etc...

Now what to do...
0
 
LVL 9

Accepted Solution

by:
prifre earned 125 total points
ID: 11898653
I dont know, but I can paste code that I use for a similar calendar:

function calendar(thedate,action)
dim rs,srch,daycolor,theclass,theevent,showex,eventtype
dim EventDate,CurrentYear,CurrentMonth,CurrentDay,FirstDay,FirstDayDate,cal,DayCounter,CorrectMonth
      if Request("eventtype")>"" then eventtype=Request("eventtype") else eventtype="news"
      if thedate="" then thedate=justnumdate(FormatDateTime(Date,vbShortDate))
      set rs=Server.CreateObject("ADODB.recordset")
      if len(thedate)<>8 then
            exit function
      end if
      select case action
            case "bookings"
                  theclass="bigcalendar"
                  showex="showbookings&amp;eventtype="&Request("eventtype")
            case "color"
                  theclass="calendar"
                  showex="showcalendar"
            case "bigcalendar"
                  theclass="bigcalendar"
                  showex="showcalendar"
            case else
                  theclass="calendar"
      end select
      EventDate=mid(thedate,5,2)&"/"&mid(thedate,7,2)&"/"&mid(thedate,1,4)
      CurrentMonth = Mid(thedate,5,2)*1
      CurrentYear = Mid(thedate,1,4)*1
      FirstDayDate = DateSerial(CurrentYear, CurrentMonth, 1)
      FirstDay = WeekDay(FirstDayDate, vbMonday)
      CurrentDay = FirstDayDate
      cal="<style type=\''text/css\''>"&vbCrLf
      cal=cal&"<!--"&vbCrLf
      rs.Open "SELECT * FROM eventtypes",conn,1,1
      while not rs.EOF
            cal=cal& "."&rs.fields("eventtype")&"_style { background-color: #"&rs.fields("eventcolor")&"; }"&vbCrLf
            rs.MoveNext
      wend
      rs.Close
      cal=cal& "-->"&vbCrLf
      cal=cal& "</style>"&vbCrLf
      call makepage(cal,"<!--styles-->")
      cal=""
      
      cal=cal& "<table border='1' cellpadding='2' cellspacing='0'>"&vbCrLf
      cal=cal& "<tr><td align='left' colspan=\''4\''><table width=\''100%\''><tr><td class=\''"&theclass&"2\''><a href='"
      cal=cal& thecode&"?sid="&sid&"&amp;ex="&showex&"&amp;date=" & justnumdate(DateAdd("m",-1,EventDate))
      cal=cal& "'>&larr;</a></td>"&vbCrLf
      cal=cal& "<td align='center' class=\''"&theclass&"\''>"&MonthName(CurrentMonth)&"</td>"&vbCrLf
      cal=cal& "<td align='right' class=\''"&theclass&"2\''><a href='"
      cal=cal& thecode&"?sid="&sid&"&amp;ex="&showex&"&amp;date=" & justnumdate(DateAdd("m",1,EventDate))
      cal=cal& "'>&rarr;</a></td></tr></table></td>"&vbCrLf
      cal=cal& "<td align='left' colspan=\''4\''><table width=\''100%\''><tr><td class=\''"&theclass&"2\''><a href='"
      cal=cal& thecode&"?sid="&sid&"&amp;ex="&showex&"&amp;date=" & justnumdate(DateAdd("m",-12,EventDate))
      cal=cal& "'>&larr;</a></td>"&vbCrLf
      cal=cal& "<td align='center' class=\''"&theclass&"\''>"&CurrentYear&"</td>"&vbCrLf
      cal=cal& "<td align='right' class=\''"&theclass&"2\''><a href='"
      cal=cal& thecode&"?sid="&sid&"&amp;ex="&showex&"&amp;date=" & justnumdate(DateAdd("m",12,EventDate))
      cal=cal& "'>&rarr;</a></td></tr></table></td>"&vbCrLf
      cal=cal& "<tr><td class=\''"&theclass&"\''>W</td>"&vbCrLf
      cal=cal&"<td class=\''"&theclass&"\''>M</td>"&vbCrLf
      cal=cal&"<td class=\''"&theclass&"\''>T</td>"&vbCrLf
      cal=cal&"<td class=\''"&theclass&"\''>O</td>"&vbCrLf
      cal=cal&"<td class=\''"&theclass&"\''>T</td>"&vbCrLf
      cal=cal&"<td class=\''"&theclass&"\''>F</td>"&vbCrLf
      cal=cal&"<td class=\''"&theclass&"\''>L</td>"&vbCrLf
      cal=cal&"<td class=\''"&theclass&"\''>S</td></tr>"&vbCrLf
      cal=cal& "<tr>"
      If FirstDay <> 1 Then
            cal=cal& "<td class=\''"&theclass&"\'' valign=\''top\''>"
            cal=cal& round((DateDiff("d","01/01/"&CurrentYear,CurrentMonth&"/01/"&CurrentYear)+WeekDay(DateSerial(mid(thedate,1,4), 1, 1), 0))/7)
            cal=cal&"</td><td colspan='" & (FirstDay-1) &"' class=\''"&theclass&"\''>&nbsp;</td>"
      End if
      DayCounter = FirstDay
      CorrectMonth = True
      While CorrectMonth = True
            if DayCounter=1 then
                  cal=cal& "<td class=\''"&theclass&"\'' valign=\''top\''>"
                  cal=cal& round((DateDiff("d","01/01/"&CurrentYear,CurrentDay)+WeekDay(DateSerial(mid(thedate,1,4), 1, 1), 0))/7)+1
                  cal=cal& "</td>"
            end if
            daycolor=""
            rs.Open "SELECT * FROM events WHERE eventdate='"&justnumdate(CurrentDay)&"'",conn,1,1
            select case action
                  case "color"
                        theevent=Day(CurrentDay)
                        if not rs.EOF then daycolor="bgcolor='#FFFF00'"
                        if Day(CurrentDay) = mid(thedate,7,2)*1 Then daycolor="bgcolor='#FF00FF'"
                        theevent="<a href='"&thecode
                        theevent=theevent&"?sid="&sid&"&amp;ex=showcalendar&amp;listdate="
                        theevent=theevent&justnumdate(CurrentMonth&"/"&Day(CurrentDay)&"/"&CurrentYear)
                        theevent=theevent&"'>"&Day(CurrentDay)&"</a>"&vbCrLf
                  case "bigcalendar"
                        daycolor="height=70 width=120 valign=\''top\'' "
                        if Day(CurrentDay) = mid(thedate,7,2)*1 Then
                              daycolor=daycolor&" bgcolor='#FF00FF'"
                        else
                              if not rs.EOF then daycolor=daycolor&" bgcolor='#FFFF00'"
                        end if
                        theevent=Day(CurrentDay)
                        while not rs.EOF
                              theevent=theevent&"<br><a href=\''"&thecode&"?ex=showcalendar&amp;ID="&rs.fields("ID")&"&amp;sid="&sid&"\''>"
                              theevent=theevent&"<span class=\''"&rs.fields("eventtype")&"_style \''>"
                              theevent=theevent&rs.fields("eventheading")&"&nbsp;"
                              theevent=theevent&"("&rs.fields("updatedby")&")"
                              theevent=theevent&"</span></a>"
                              rs.MoveNext
                        wend
                        theevent=theevent&"<br><a href=\''"&thecode&"?ex=showcalendaradd&date="&justnumdate(CurrentDay)&"&sid="&sid&"\''>Add</a>"
                  case "bookings"
                        daycolor="height=70 width=120 valign=\''top\'' "
                        if Day(CurrentDay) = mid(thedate,7,2)*1 Then
                              daycolor=daycolor&" bgcolor='#FF00FF'"
                        end if
                        theevent=Day(CurrentDay)
                        while not rs.EOF
                              if eventtype=rs.fields("eventtype") then
                                    theevent=theevent&"<br><a href=\''"&thecode&"?ex=showbookings&amp;ID="&rs.fields("ID")&"&amp;sid="&sid&"\''>"
                                    theevent=theevent&"<span class=\''"&rs.fields("eventtype")&"_style \''>"
                                    theevent=theevent&rs.fields("eventheading")&"&nbsp;"
                                    theevent=theevent&"("&rs.fields("updatedby")&")"
                                    theevent=theevent&"</span></a>"
                              end if
                              rs.MoveNext
                        wend
                        theevent=theevent&"<br><a href=\''"&thecode&"?ex=showbookingadd&sid="&sid&"&amp;date="&justnumdate(CurrentDay)&"&amp;eventtype="&eventtype&"\''>Add</a>"
                  case else
            end select
            rs.Close
            cal=cal& "<td "&daycolor&" class=\''"&theclass&"\''>"&vbCrLf
            cal=cal&theevent
            cal=cal&"</td>"&vbCrLf
            DayCounter = DayCounter + 1
            if DayCounter > 7 then
                  DayCounter = 1
                  cal=cal& "</tr><tr>"
            end if
            CurrentDay = DateAdd("d", 1, CurrentDay)
            if Month(CurrentDay) <> CurrentMonth then
               CorrectMonth = False
            end if
      wend
      if DayCounter <> 1 Then
         cal=cal& "<td colspan=\''"&8-DayCounter&"\'' class=\''"&theclass&"\''>&nbsp;</td>"
      end if
      cal=cal& "</tr></table>"
      calendar = Replace(cal,"\''",chr(34))
end function

It is a part of my code, wich produces the calendar. I remember I searched for various calendar samples and found something I based my code on.

perhaps it will help.

with a smile
/prifre

0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

747 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

10 Experts available now in Live!

Get 1:1 Help Now