DateToNum

From CometWiki

Revision as of 18:20, 7 December 2010 by Jim (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

DATETONUM function

Syntax: DATETONUM(date-string,numeric-error-argument)

Discussion: The DATETONUM function converts a date-string to a 6-digit date serial number.

Prior to Comet version 504.201, DATETONUM expected an 8-byte string in the following format: MMDDYYYY

From 504.201 on, the DATETONUM function will also process a 6-byte string in the following form: MMDDYY, and the date-to-number conversion proceeds as follows:

If YY is greater than or equal to the sliding year value (from the system configuration file), the number returned by DATETONUM uses the sliding century value (it adds this to the YY value). Thus, using the default value, MMDDYY assumes the century to be 1900.

If YY is less than the sliding year value, the number returned by DATETONUM is the sliding century plus 100 years. For current CFIG files, the default values (1900 and 40) are assumed. In either case, the resulting date serial number is a 6-digit value that represents the number of days elapsed from a given base date. The base date is January 1, 1800. The greatest date covered by this function is December 31, 2299. The following chart demonstrates these values.

 Date                Date string     Date serial number
 ------------------------------------------------------
 January 1, 1800     "01011800"      0
 December 31, 2299   "12312299"      182620

The DATETONUM function validates calendar dates (e.g., 12 months in a year, valid number of days per month). It also makes sure that the date falls within the limits shown in the previous chart. If the date-string is a valid date, the numeric-error-argument equals 0, otherwise it equals 1.

The DATETONUM function respects the rules for leap years (i.e., the years 1800 and 1900 were not leap years, but the year 2000 is a leap year).

Note: The NUMTODATE function converts a serial number to a date string.

Also see DATE2NUM and NUM2DATE.

Application note: The DATETONUM function can simplify the date computation algorithms in your Internet Basic programs. For example, to compute the number of days between two dates, you simply convert both dates to their equivalent date serial numbers, then subtract one value from the other. Example:

 LENGTH   8 & LOCAL VALUE$
 LENGTH 6.0 & LOCAL SERIAL
 LENGTH 1.0 & LOCAL ERRARG
 .
 PRINT (0) "ENTER A DATE STRING (MMDDYYYY OR MMDDYY):"
 INPUT (0) VALUE$
 IF VALUE$ = "" THEN RUN "QMONITOR"
 SERIAL = DATETONUM(VALUE$,ERRARG)
 PRINT (0) "THE DATE SERIAL NUMBER IS:";SERIAL
 PRINT (0) "THE ERROR ARGUMENT IS:";ERRARG
Personal tools