[an error occurred while processing this directive]

HP OpenVMS Systems Documentation

Content starts here

HP COBOL
Reference Manual


Previous Contents Index

7.9 CURRENT-DATE

Description

The CURRENT-DATE function returns a 21-character alphanumeric value that represents the calendar date and the time of day.


Rules

  1. The type of this function is alphanumeric.
  2. The contents of the character positions returned, numbered from left to right, are as follows:
    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.)

Example

The COBOL syntax for this function (similar to the example) is common to all platforms:


MOVE FUNCTION CURRENT-DATE TO RSULT.


199701101652313200000
This is a sample value returned by the example CURRENT-DATE function. Reading from left to right, it shows
  • The year, 1997
  • The month, January
  • The day of the month, the 10th

  • The time of day, 16:52 (4:52 P.M.)
  • The seconds, 31, and the hundredths
    of seconds, 32, after 16:52:31

7.10 DATE-OF-INTEGER

Description

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.

Rules

  1. The type of this function is integer.
  2. The returned value represents the ISO Standard date, in the form YYYYMMDD, that is equivalent to the integer specified. YYYY is an integer in the range 1601 through 9999. MM is an integer in the range 1 through 12. DD is an integer in the range 1 through 31.

Example


COMPUTE RSULT = FUNCTION DATE-OF-INTEGER (20).
The value returned and stored in RSULT (a numeric integer data item) is


16010120
This value represents January 20, 1601, which is 20 days after December 31, 1600.

7.11 DATE-TO-YYYYMMDD

Description

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.

Rules

  1. The type of this function is integer.
  2. The returned value is an integer representing YYYYMMDD and is calculated as follows:


              YY = int(arg-1 / 10000)
              mmdd = mod (arg-1, 10000)
              return FUNCTION YEAR-TO-YYYY(YY, arg-2) * 10000 + mmdd
    

Example


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

Description

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.

Rules

  1. The type of this function is integer.
  2. The returned value is an integer of the form YYYYDDD, where YYYY represents a year in the Gregorian calendar and DDD represents the day of that year. YYYY is an integer in the range 1601 through 9999. DDD is an integer in the range 1 through 366.

Example


COMPUTE RSULT = FUNCTION DAY-OF-INTEGER (28).
The value returned and stored in RSULT (a numeric integer data item) shows the 28th day of the year 1601 (that is, 28 days succeeding December 31, 1600), as follows:


1601028

7.13 DAY-TO-YYYYDDD

Description

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.

Rules

  1. The type of this function is integer.
  2. The returned value is an integer representing YYYYDDD and is calculated as follows:


              YY = int(arg-1 / 1000)
              ddd = mod (arg-1, 1000)
              return FUNCTION YEAR-TO-YYYY(YY, arg-2) * 1000 + ddd
    

Example


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".
DAY-TO-YYYYDDD 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 for 1999 arg-2 has the value 101. If arg-1 is 50111, the returned-value is 2050111. If arg-1 is 99111, the returned-value is 2099111.


Previous Next Contents Index