[an error occurred while processing this directive]
HP OpenVMS Systems Documentation |
HP COBOL
|
Previous | Contents | Index |
The CURRENT-DATE function returns a 21-character alphanumeric value that represents the calendar date and the time of day.
Character Positions | Contents |
---|---|
1-4 | Four numeric digits of the year in the Gregorian calendar. |
5-6 | Two numeric digits of the month of the year, in the range 01 through 12. |
7-8 | Two numeric digits of the day of the month, in the range 01 through 31. |
9-10 | Two numeric digits of the hours past midnight, in the range 00 through 23. |
11-12 | Two numeric digits of the minutes past the hour, in the range 00 through 59. |
13-14 | Two numeric digits of the seconds past the minute, in the range 00 through 59. |
15-16 | Two numeric digits of the hundredths of a second past the second, in the range 00 through 99. |
17-21 | The value 00000. (Reserved for future use.) |
The COBOL syntax for this function (similar to the example) is common to all platforms:
MOVE FUNCTION CURRENT-DATE TO RSULT. |
199701101652313200000 |
The DATE-OF-INTEGER function converts a date from an integer date form representing the number of days after December 31, 1600, to standard date form (YYYYMMDD).
num-days
is a positive integer argument that represents a number of days succeeding December 31, 1600, in the Gregorian calendar.
COMPUTE RSULT = FUNCTION DATE-OF-INTEGER (20). |
16010120 |
The DATE-TO-YYYYMMDD function converts a date in the form YYMMDD to the form YYYYMMDD. An optional second argument, when added to the current year (at the time the program executes), defines the ending year of a 100-year interval. This interval determines to what century the two-digit year belongs.
General Format
FUNCTION DATE-TO-YYYYMMDD ( arg-1 [ arg-2 ] ) |
arg-1
is a nonnegative integer between 0 and 999999.arg-2
is an integer. Its value, when added to the current year, must be between 1700 and 9999. If it is omitted, the default value is 50.
YY = int(arg-1 / 10000) mmdd = mod (arg-1, 10000) return FUNCTION YEAR-TO-YYYY(YY, arg-2) * 10000 + mmdd |
IF FUNCTION DATE-TO-YYYYMMDD (801123, 50 ) = 19801123 DISPLAY "correct". IF FUNCTION DATE-TO-YYYYMMDD (801123, 100 ) = 20801123 DISPLAY "correct". IF FUNCTION DATE-TO-YYYYMMDD (801123, -100 ) = 18801123 DISPLAY "correct". |
DATE-TO-YYYYMMDD implements a sliding window algorithm. To use it for a fixed window, you can specify arg-2 as follows:
(fixed-ending-year - function numval (function current-date (1:4))) |
If fixed-ending-year is 2100, then in 1999 arg-2 has the value
101. If arg-1 is 501123, the returned-value is 20501123. If
arg-1 is 991123, the returned-value is 20991123.
7.12 DAY-OF-INTEGER
The DAY-OF-INTEGER function converts a date from an integer date form representing the number of days succeeding December 31, 1600, to a date form (sometimes called "Julian") representing year and days (YYYYDDD).
num-days
is a positive integer argument that represents a number of days succeeding December 31, 1600, in the Gregorian calendar.
COMPUTE RSULT = FUNCTION DAY-OF-INTEGER (28). |
1601028 |
The DAY-TO-YYYYDDD function converts a date in the form YYDDD to the form YYYYDDD. An optional second argument, when added to the current year (at the time the program executes), defines the ending year of a 100-year interval. This interval determines to what century the two-digit year belongs.
General Format
FUNCTION DAY-TO-YYYYDDD ( arg-1 [ arg-2 ] ) |
arg-1
is a nonnegative integer between 0 and 99999.arg-2
is an integer. Its value, when added to the current year, must be between 1700 and 9999. If it is omitted, the default value is 50.
YY = int(arg-1 / 1000) ddd = mod (arg-1, 1000) return FUNCTION YEAR-TO-YYYY(YY, arg-2) * 1000 + ddd |
IF FUNCTION DAY-TO-YYYYDDD (80111, 50 ) = 1980111 DISPLAY "correct". IF FUNCTION DAY-TO-YYYYDDD (80111, 100 ) = 2080111 DISPLAY "correct". IF FUNCTION DAY-TO-YYYYDDD (80111, -100 ) = 1880111 DISPLAY "correct". |
(fixed-ending-year - function numval (function current-date (1:4))) |
Previous | Next | Contents | Index |