Wednesday, December 12, 2012

Convert Gregorian Date (YYYYMMDD) to Julian date(YYYDDD) and vice versa

 

The easiest ways to convert Julian date (YYYYDDD) to Gregorian equivalent is using COBOL Intrinsic functions.

Here is the function and its descriptions.

Function Description
DATE-OF-INTEGER Gregorian date equivalent (YYYYMMDD) of integer date
DAY-OF-INTEGER Julian date equivalent (YYYYDDD) of integer date
INTEGER-OF-DATE Integer date equivalent of Gregorian date (YYYYMMDD)
INTEGER-OF-DAY Integer date equivalent of Julian date(YYYYDDD)
*** The integer date is a seven-digit integer with a range from 1 to 3,067,671. (dates ranging from January 1, 1601 thru December 31, 9999).
The Gregorian date is obtained from the calculation (YYYY * 10,000) + (MM * 100) + DD.
o YYYY represents the year. It must be an integer greater than 1600, but not greater than 9999.
o MM represents a month and must be a positive integer less than 13.
o DD represents a day and must be a positive integer less than 32, provided that it is valid for the specified month and year combination.

The returned value of INTEGER-OF-DATE/DAY functions is an integer that is the number of days the date represented by given input, succeeds December 31, 1600 in the Gregorian calendar.

Sample Program

IDENTIFICATION DIVISION.
PROGRAM-ID.  DTECNV.
DATA DIVISION.

WORKING-STORAGE SECTION.
01 WS-WORK-AREA.
     05 WS-GREG-DATE                  PIC  9(08).
     05 WS-JULN-DATE                  PIC  9(07).
     05 WS-INT-DATE                   PIC  9(07).
PROCEDURE DIVISION.

A0100-MAIN-PARA.
     ACCEPT  WS-GREG-DATE.
*  Gregorian date YYYYMMDD To Julian date  YYYYDDD
     COMPUTE WS-INT-DATE  = FUNCTION INTEGER-OF-DATE(WS-GREG-DATE)
     COMPUTE WS-JULN-DATE = FUNCTION DAY-OF-INTEGER(WS-INT-DATE).
     DISPLAY 'GREGORIAN DATE        : '  WS-GREG-DATE.
     DISPLAY 'JULIAN    DATE        : '  WS-JULN-DATE.

     ACCEPT  WS-JULN-DATE.
*  Julian Date YYYYDDD To Gregorian Date YYYYMMDD**
     COMPUTE WS-INT-DATE  = FUNCTION INTEGER-OF-DAY(WS-JULN-DATE)
     COMPUTE WS-GREG-DATE = FUNCTION DATE-OF-INTEGER(WS-INT-DATE)
     DISPLAY 'JULIAN    DATE        : '  WS-JULN-DATE.
     DISPLAY 'GREGORIAN DATE        : '  WS-GREG-DATE.
     STOP RUN.

 

Output

image

Hey Guys. if my tutorial helped you please support me by liking my facebook page, sharing this webpage with your friends and commenting below. If you want me to update or add me some specific tutorial please cooment to this page or email me at shibuthannikkunnath@gmail.com

-Cheers – Shbibu Thannikkunnath

No comments:

Post a Comment