Scriptcalendar.com
An Incredible Javascript Event Calendar

User Guide

»  Table Of Contents

Events across a Range of Days

Section 3.4.3

You may have a need to write an event that spans two months or several months. The reoccuring code already presented is inadequate for such events.

Instead, you need to turn to a concept called a "ymd" date. Ymd stands for year-month-day. It means that instead of writing a date like 01/01/2010, you write it year first, follwed by the month and finally the day. The same date becomes 2010-01-01. Last, we can remove the dashes to have the number 20100101.

When you write dates in this ymd format, you can do numeric comparisons. Like 12/31/2008 is less than 01/01/2009 ( 20081231 < 20090101) or 5/1/2009 is less than 9/20/2009 (20090501 < 20090920).

You change the date being rendered to the ymd numeric date in the spspcevt.js. The date passed to the scspcevt.js is the "dte" variable. To translate this javascript date into a ymd numeric value, you can call a method on date values. This method is added by the Scriptcalendar engine. Please see the the code below.

var numericDate = dte.format("yymmdd");

Now you can use this ymd numeric to your advantage. Imagine you need an event from 5/1/2009 through 9/20/2009. We can translate these values in ymd numeric values. They become 20090501 and 20090920 respectively. To check if we are in the range, we just compare the numeric values.

// lunch event between 5/1/09 and 9/20/09
var numericDate = dte.format("yymmdd");
if (numericDate >= 20090501 && numericDate <= 20090920)
{
    objEvent = new EventObj(m,d,y, "Lunch", null, "scEventBlue");
    arrEvents[arrEvents.length] = objEvent;
}

»  Table Of Contents