| Introduction | MTB Statements | File System | Compiler | Applications | Reference Guide | Index |
| Language Structure | Data Division | I/O Format Division | Procedure Division | Mnemonics |
| 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 variable that serves two purposes:
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 is a leap year). 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 MTB 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 DATESTING$ 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:" ; SERIAL PRINT (0) "The error argument is:" ; DATEMODEThe following table shows how various input values would be converted by the above program: Input: Results: DATESTRING$ DATEMODE SERIAL DATEMODE ============================================= "7/4/98" 0 72502 0 "7/4/1998" 0 72502 0 "070498" 0 72502 0 "07041998" 0 72502 0 "04071998" 1 72502 0 "19980704" 2 72502 0 "19980407" 3 72502 0 "7/4/01" 0 73598 0 "7/4/2001" 0 73598 0 "070401" 0 73598 0 "07042001" 0 73598 0 "123456" 0 0 1 |