| Introduction | MTB Statements | File System | Compiler | Applications | Reference Guide | Index |
| Language Structure | Data Division | I/O Format Division | Procedure Division | Mnemonics |
| Syntax: | NUM2DATE(numeric-argument, date-mode) |
| Discussion: |
The NUM2DATE function converts a date serial number to the
corresponding date string.
The numeric-argument is a 6-digit value (variable or constant) 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 serial number Date string Notes
==================================================
0 "01011800" Base date
182620 "12312299" Maximum value
When using date-mode 0 through 3, if the value of the numeric-argument is less than 0 or greater than 182620, the NUM2DATE function will return an 8-byte string containing the following values: "000000" The date-mode is a numeric value that determines the format of the resulting date-string. Date-mode Format of resulting date-string Length of result ============================================================== 0 MMDDYYYY 8 bytes 1 DDMMYYYY 8 bytes 2 YYYYMMDD 8 bytes 3 YYYYDDMM 8 bytes 4 * Day, DD-Mon-YYYY HH:MM:SS GMT 29 bytes* Date-mode 4 is the standard format for Internet dates. When used on the current date, this function returns the day of the week (3-character abbreviation), date (formatted as shown, with 3-character abbreviation for the month), and time. The time is expressed as Greenwich Mean Time (GMT) and is based on the current value of the TIME$ system variable. The NUM2DATE 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 DATE2NUM function converts a date string into a date serial number. |
| History: |
This function was added in Comet version 504.233 and Comet98 Build 233.
Date mode 4 was added in Comet98 Build 266. |
| Example: |
The following program demonstrates date-modes 0 through 3:
LENGTH 8 & LOCAL DATESTING$ LENGTH 1.0 & LOCAL DATEMODE LENGTH 6.0 & LOCAL SERIAL . . . PRINT (0) "Enter a date serial number (######):" INPUT (0) SERIAL PRINT (0) "Enter a date mode (0-3):" INPUT (0) DATEMODE DATESTRING$ = NUM2DATE(SERIAL, DATEMODE) PRINT (0) "The date string is:" ; DATESTRING$The following table shows how various input values would be converted by the above program: Input: Result: SERIAL DATEMODE DATESTRING$ ============================================================== 72502 0 "07041998" 72502 1 "04071998" 72502 2 "19980704" 72502 3 "19980407" 73598 0 "07042001" 73598 1 "04072001" 73598 2 "20010704" 73598 3 "20010407" 99999 0 "10152073" 182620 0 "12312299" 182621 0 "00000000" |