[thelist] automatic 'calendar in a table' script

.jeff jeff at members.evolt.org
Fri Jan 11 19:49:02 CST 2002


joel,

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> From: spinhead
>
> We have lots of pages on our intranet that would just
> look better and be more intuitive if they were
> displayed as a year-on-a-page calendar instead of just
> lists of dates. Anyone know of a script before I write
> one?
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

I have a feeling you're not talking about something like this:

http://members.evolt.org/jeff/code/calendar/index.cfm

but just in case you are, there it is.  don't let the ".cfm" throw ya
though.  it's just javascript, some fancy dhtml, and some internet explorer
technology.

in case that's not what you're after, but rather a full page display, here's
a tip for building it yourself:

<tip type="ColdFusion" author=".jeff">

i've designed *many* applications that use calendars.  in all this
development i've tried many different methods for creating the layout.  i
think after all this time i've finally landed on what seems to be the most
efficient.  would you believe it only requires a single loop for the actual
date output?

<cfscript>
  year = Year(Now());
  month = Month(Now());

  writeOutput('<table>');
  writeOutput('<tr><td colspan="7" align="center">');
  writeOutput(MonthAsString(month));
  writeOutput('</td></tr>');
  writeOutput('<tr>');
  for(i = 1; i LTE 7; i = i + 1)
  {
    writeOutput('<td align="center">' & Left(DayOfWeekAsString(i), 2) &
'</td>');
  }
  writeOutput('</tr>');

  dayofweek = DayOfWeek(CreateDate(year, month, 1));
  daysinmonth = DaysInMonth(CreateDate(year, month, 1));
  for(i = 1; i LT 43; i = i + 1)
  {
    if(NOT (i - 1) MOD 7)
      writeOutput('<tr>');
    if(i LT dayofweek OR i GT daysinmonth + dayofweek - 1)
      writeOutput('<td width="19">&nbsp;</td>');
    else
    {
      date = i - dayofweek + 1;
      writeOutput('<td width="19">' & date & '</td>');
      if(NOT i MOD 7)
        writeOutput('</tr>');
    }
  }
  writeOutput('</table>');

</cfscript>

take a couple of minutes and turn this into a user-defined function.  now
you just have to pass in the month and year and the function does the rest
of the work.

</tip>

and yes, joel, you could convert this to asp quite easily.  the important
thing to note is that there's only a single loop.

enjoy,

.jeff

http://evolt.org/
jeff at members.evolt.org
http://members.evolt.org/jeff/






More information about the thelist mailing list