Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Processing Date entries 4

Status
Not open for further replies.

IVA30

Programmer
Dec 22, 2005
1
CA
Hi everyone,

I am looking for a COBOL command to separate a given date (stored in a 8 digit variable under the form YYYY-MM-DD) into three separate variables one for the year, the month and the day. Can anybody help me with this?

Thanks
I.V.
 
[tt]01 given-date.
03 given-year PIC 9(4).
03 given-month PIC 99.
03 given-day PIC 99.[/tt]

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Code:
01  some-date pic 9(8).
01  redefines some-date.
    02  some-year pic 9(4).
    02  some-month pic 9(2).
    02  some-day pic 9(2).
Just learning COBOL?
 
And if the 8 digits are really stored as YYYY-MM-DD (ie in a X(10)):[tt]
01 given-date.
03 given-year PIC 9(4).
03 FILLER PIC X.
03 given-month PIC 99.
03 FILLER PIC X.
03 given-day PIC 99.[/tt]

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
An other way - certainly not the best - is to use reference modification. In that way, you use a command to separate.

Source example:

Code:
WORKING-STORAGE SECTION.                                   
01  YYYY-MM-DD                     PIC 9(8) VALUE 20051228.
PROCEDURE DIVISION.                                        
0000.                                                      
    DISPLAY 'YEAR = ' YYYY-MM-DD(1:4)                      
          ' MONTH = ' YYYY-MM-DD(5:2)                      
            ' DAY = ' YYYY-MM-DD(7:2)                      
    .

Output:

YEAR = 2005 MONTH = 12 DAY = 28

Regards,

Crox
 
ACCEPT IN-DATE

IN-YEAR = IN-DATE (1:4)
IN-MONTH = IN-DATE (5:2)
IN-DAY = IN-DATE (7:2)

If you do not like my post feel free to point out your opinion or my errors.
 
ceh4702,
As your tag line invites people to point out any errors, I've got to mention that your code isn't Cobol!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top