Introduction | Language Structure | IB Statements | File System | Comet 32 Runtime | Index |
| Syntax: | DATE2NUM(date-string,date-mode) |
| Discussion: |
The DATE2NUM function converts a date-string to a
6-digit date serial number.
DATE2NUM performs the following steps before converting the date-string:
For example, a date-string of "5/1/98" would be converted to "05011998" and then converted to the corresponding date serial number. The date-mode is a 1-digit numeric value that indicates the format of the date-string (after the above preparatory conversion steps have been performed). The following chart shows the accepted date-mode values: Date-mode Date-string Date-string format Value format (with sliding year logic) =================================================== 0 MMDDYYYY MMDDYY 1 DDMMYYYY DDMMYY 2 YYYYMMDD YYMMDD 3 YYYYDDMM YYDDMMNote: The date-mode is not an error argument; this function does not change the value of the date-mode. DATE2NUM returns a date serial number 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 respects the rules for leap years (i.e., the years 1800 and 1900 were not leap years, but the year 2000 was a leap year). If the date string contains an invalid date, the DATE2NUM function returns a 1- as the date serial number. The NUM2DATE function converts a date serial numer to a date string. |
| Sliding year logic: |
If the date-string contains a 2-byte year (e.g., "98"),
rather than a full 4-byte year (e.g., "1998"), Comet
applies the following sliding year logic:
|
| Application note: | The DATE2NUM 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. |
| History: | This function was added in Comet version 504.233 and Comet98 Build 233. |
| Example: |
LENGTH 12 & LOCAL DATESTRING$ LENGTH 1.0 & LOCAL DATEMODE LENGTH 6.0 & LOCAL SERIAL . . . PRINT (0) "Enter a date string:" INPUT (0) DATESTRING$ PRINT (0) "Enter a date mode (0-3):" INPUT (0) DATEMODE SERIAL = DATE2NUM(DATESTRING$, DATEMODE) PRINT (0) "The date serial number is:" ; SERIALThe following table shows how various input values would be converted by the above program: Input: Result: DATESTRING$ DATEMODE SERIAL ================================== "7/4/98" 0 72502 "7/4/1998" 0 72502 "070498" 0 72502 "07041998" 0 72502 "04071998" 1 72502 "19980704" 2 72502 "19980407" 3 72502 "7/4/01" 0 73598 "7/4/2001" 0 73598 "070401" 0 73598 "07042001" 0 73598 "123456" 0 1- (invalid date) |