SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: calendar dates

  1. #1
    SitePoint Addict AshleyH's Avatar
    Join Date
    Mar 2005
    Posts
    260
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    calendar dates

    I have a mysql database with a datefrom and dateto field.

    These contain dates for when I reserve something for example if I want a widget for 3 days from the 1st Nov to the 3rd Nov the fromdate would have '11/01/2006' and to '11/03/2006' .

    What I need to do is represent that this has been reserved on screen using a some a simple calendar I have made which makes the background of each date red. Is it possible for the calendar to realise that the dates that need to be reserved are the 1st, 2nd, and 3rd?

    Thanks for your help!

  2. #2
    SitePoint Addict AshleyH's Avatar
    Join Date
    Mar 2005
    Posts
    260
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is the code I have got:

    Code:
    <!--- Determine what date to show, and last viewed Date if applicable.--->
    <cfparam name="CurntDate" default="#now()#">
    <cfif isdefined("MonthChange")>
    	<cfif monthchange is 'forward'>
    		<cfset curntdate = createodbcdate(dateadd("m", 1, lastdate))>
    	<cfelse>
    		<cfset curntdate = createodbcdate(dateadd("m", -1, lastdate))>
    	</cfif>
    </cfif>
    <cfparam name="YearSet" default="#year(CurntDate)#">
    <cfparam name="MonthSet" default="#month(CurntDate)#">
    
    <!--- Create the date variables to search the Database by. --->
    <cfset monthstart = createdatetime(#yearset#, #monthset#, 1, 0, 0, 0)>
    <cfset monthend = createdatetime(#yearset#, #monthset#, #daysinmonth(monthstart)#, 23, 59, 59)>
    
    <cfquery datasource="#dsn#" name="SearchResults">
    	Select EventName, Calendar_ID, CalendarDate 
    	From Calendar
      Where CalendarDate Between #MonthStart# and #MonthEnd#
    </cfquery>
    <!---
       Code for calculating the days format to display
    																														 --->
    <cfset offset = #dayofweek(monthstart)#>
    <cfset lastslot = #offset# + #daysinmonth(monthstart)#-1>
    <cfset caldays = (#ceiling(lastslot/7)#)*7>
    <cfset day = 1>
    <html>
    <head>
    	<title>Calendar for <cfoutput>#DateFormat(CurntDate,"mm/dd/yyyy")#</cfoutput></title>
    </head>
    <body bgcolor="#FFFFFF" link="#666633" vlink="#666633">
    
    	<!--- insert calendar table --->
    	<table width="500" border=0 cellpadding=0 cellspacing=0 bgcolor="ffffff">
    	<tr>
    	<td>
    	<!--- previous table is white background (shell) --->
    	<table border="1">
    	<tr align="center">
    		<cfoutput>
    			<td colspan="1" align="center"> 
    				<a href="calendar.cfm?MonthChange=Backward&LastDate=#DateFormat(CurntDate, "mm/dd/yyyy")#&Action=ShowCalendar"><font size="2">&lt;&lt;</font></a>
    			</td>
    			<td colspan="5" align="center"><font size="2" color="##333366"><b>#DateFormat(CurntDate,"MMMM yyyy")#</b></font></td>
    			<td>
    				<a href="calendar.cfm?MonthChange=Forward&LastDate=#DateFormat(CurntDate, "mm/dd/yyyy")#&Action=ShowCalendar"><font size="2">&gt;&gt;</font></a>
    			</td>
    		</cfoutput>
    	</tr>
    	
    	<tr>
    		<td align="center"><font style="font:12px arial;color:660000;">S</font></td>
    		<td align="center"><font style="font:12px arial;color:660000;">M</font></td>
    		<td align="center"><font style="font:12px arial;color:660000;">T</font></td>
    		<td align="center"><font style="font:12px arial;color:660000;">W</font></td>
    		<td align="center"><font style="font:12px arial;color:660000;">T</font></td>
    		<td align="center"><font style="font:12px arial;color:660000;">F</font></td>
    		<td align="center"><font style="font:12px arial;color:660000;">S</font></td>
    	</tr>
    	
    	<tr>
    		<cfloop index="ii" from="1" to="#CalDays#">
    			<cfif #ii# gte #offset# and #ii# lte #lastslot# >
    				<td valign=top 
    				 <cfif day is #datepart("d", now())# and #month(curntdate)# is #month(now())#>bgcolor="003399"</cfif>>
    					<cfoutput>
    					<cfif day is #datepart("d", now())# and #month(curntdate)# is #month(now())#>
    						<font style="font: 12px arial;color:ffffff;"><b>#Day#</b></font>
    					<cfelse>
    						<font style="font: 12px arial;color:003399;">#Day#</font>
    					</cfif><br>
    					</cfoutput>
    					<cfoutput query="SearchResults">
    						<cfif #day# is '#day(calendardate)#'>
    							<a href="index.cfm?Calendar_ID=#Calendar_ID#&CurntDate=#DateFormat(CurntDate, "mm/dd/yyyy")#&Action=ShowEvent">#EventName#</a><p> 
    						</cfif>
    					</cfoutput>
    				</td>
    				<cfset day = #day# + 1>
    			<cfelse>
    				<td width="15"></td>
    			</cfif>
    			
    			<cfif (#ii# mod 7 is 0)>
    			</tr>
    			<tr>
    			</cfif>
    		</cfloop>
    	
    	<!--- The last TR is created in the loop above --->
    	<td colspan="7"></td>
    	</tr>
    	</table>
    	</td>
    	</tr>
    </table>
    	<!--- /insert calendar table --->


Bookmarks

Posting Permissions

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