(and it seems to be overly complicated code for what you are trying to achieve)
That got me thinking and I came up with the following custom tag to display a monthly calendar. It doesn't support styles yet or flag events, but it does allow you to start the calendar on any day of the week and it produces a calendar for any given date. It doesn't support being called with a closing tag either. I think it's simpler and cleaner but feel free to disagree.
Regards, Sean
<!---
attributes
start optional day of week on which to start calendar
default sunday (1)
when optional any date in the month to be displayed
default today (hence, this month)
examples
this month's calendar, starting on a sunday:
<cf_calendar>
this december's calendar, starting on a monday:
<cf_calendar start="2" when="#createDate(2004,12,1)#">
---><cfparam name="attributes.start" type="numeric" default="1" /> <cfparam name="attributes.when" type="date" default="#now()#" />
<!--- useful constants for the calendar ---> <cfset variables.weekDays = "SMTWTFSSMTWTFS" />
<!--- initialization --->
<cfset variables.selectedYear = datePart("yyyy",attributes.when) />
<cfset variables.selectedMonth = datePart("m",attributes.when) />
<cfset variables.firstOfTheMonth = createDate(variables.selectedYear,variables.selectedMonth,1) />
<cfset variables.dowFirst = dayOfWeek(variables.firstOfTheMonth) />
<cfset variables.today = now() />
<cfif variables.selectedYear eq datePart("yyyy",variables.today) and
variables.selectedMonth eq datePart("m",variables.today)>
<!--- today could be in the calendar --->
<cfset variables.dayToday = datePart("d",variables.today) />
<cfelse>
<!--- today cannot be part of calendar so set it to zero so it won't match --->
<cfset variables.dayToday = 0 />
</cfif>
<!--- figure out the first date on the calendar --->
<cfset variables.calendarDate = dateAdd("d",attributes.start - variables.dowFirst,variables.firstOfTheMonth) />
<cfif attributes.start gt variables.dowFirst>
<cfset variables.calendarDate = dateAdd("d",-7,variables.calendarDate) />
</cfif>
<cfoutput>
<table border="1" cellpadding="1" cellspacing="1">
<!--- build the calendar header --->
<tr>
<cfloop index="variables.dow" from="1" to="7">
<th>#mid(variables.weekDays,variables.dow - 1 + attributes.start,1)#</th>
</cfloop>
</tr>
<cfloop index="variables.row" from="1" to="6">
<tr>
<cfloop index="variables.dow" from="1" to="7">
<cfset variables.day = datePart("d",variables.calendarDate) />
<cfset variables.month = datePart("m",variables.calendarDate) />
<cfif variables.selectedMonth eq variables.month>
<cfif variables.dayToday eq variables.day>
<td style="color: red">#variables.day#</td>
<cfelse>
<td>#variables.day#</td>
</cfif>
<cfelse>
<td style="color: grey">#variables.day#</td>
</cfif>
<cfset variables.calendarDate = dateAdd("d",1,variables.calendarDate) />
</cfloop>
</tr>
<!--- if we're into the next month now, we're done --->
<cfif datePart("m",variables.calendarDate) gt variables.selectedMonth>
<cfbreak />
</cfif>
</cfloop>
</table>
</cfoutput>
--- You are currently subscribed to cfaussie as: [EMAIL PROTECTED] To unsubscribe send a blank email to [EMAIL PROTECTED]
MXDU2004 + Macromedia DevCon AsiaPac + Sydney, Australia http://www.mxdu.com/ + 24-25 February, 2004
