IsDate, DateAdd, and
Compatibility: the functions should work in any modern browser. The demo itself works in IE and Firefox at least.
Usage: copy the file to your project, link to it, and you can begin using the functions just as in VBScript.
Limitations: in VBScript, DateDiff and DatePart() accept the
option parameter FirstWeekOfYear.
jsDate ignores this, and assumes Sunday & the week of January 1st (which are VBScript's defaults).
Enhancements: jsDate's DateAdd and
DateDiff functions can track Milliseconds (unlike VBScript). I've also added a
Format function emulating the same in VB6 (date-features only). This should fill the gaps in
FormatDateTime (which wraps Format anyway).
Other differences: jsDate's IsDate has different tolerances than VBScript's.
disallows other date formats which VBScript accepts (e.g. yearless dates, dateless time, and dash or dot date separators).
I added the new CDate implementation for this reason.
It turns out that VBScript's DateDiff does not check that each YYYY, M, or Q interval has been completed,
but just if it has rolled over into a new one. So in VBScript, DateDiff("yyyy", "12/31/2000", "1/1/2001")
returns 1 (even though it's just 1 day completed, not a year). As of v0.94, jsDate's
DateDiff now behaves this way too. One exception is the Q interval, which still checks for 3
months completed (does anyone really use Q?).
maybe TODO: better documentation; make jsDate's IsDate tolerances more like VBScript's; implement FirstWeekOfYear parameter; implement Now; implement DateSerial/DateValue/Time/TimeSerial/TimeValue?;