Geeting Current Date in a COBOL program.

OS/VS COBOL, COBOL II, Enterprise COBOL for z/OS. OpenCOBOL and OOCobol.
Post Reply
Shahid
Registered Member
Posts: 47
Joined: Sun Aug 25, 2013 1:00 am

Geeting Current Date in a COBOL program.

Post by Shahid »

Hello,

To get the current-date from system date and to display it, I am using below code:

Code: Select all

PROCEDURE DIVISION. 
01-DATE-PARA.            
    ACCEPT WS-DATE FROM DATE.        
    DISPLAY 'THE DATE: ' WS-DATE. 
 
It displays the date as "150921" but I want it to be displyed like: "20150921". What change do I need to get it? Please help.

Thanks.
zprogrammer
Global Moderator
Global Moderator
Posts: 588
Joined: Wed Nov 20, 2013 11:53 am
Location: Mars

Re: Geeting Current Date in a COBOL program.

Post by zprogrammer »

Quoting the syntax from Enterprise cobol manual

Code: Select all

   ___ Format 2: system information transfer ________________________________________________________  
  |                                                                                                  |
  | >>__ACCEPT__identifier-2__FROM__ _DATE__ __________ _ ________________________________________>< | 
  |                                 |       |_YYYYMMDD_| |                                           | 
  |                                 |_DAY__ _________ ___|                                           | 
  |                                 |      |_YYYYDDD_|   |                                           | 
  |                                 |_DAY-OF-WEEK________|                                           | 
  |                                 |_TIME_______________|                                           | 
  |                                                                                                  |
  |__________________________________________________________________________________________________|
 

zprogrammer
William Collins
Global Moderator
Global Moderator
Posts: 490
Joined: Sun Aug 25, 2013 7:24 pm

Re: Geeting Current Date in a COBOL program.

Post by William Collins »

There is also an intrinsic function, CURRENT-DATE, which you may want to look at, which has more extensive information than is returned by ACCEPT DATE YYYYMMDD.
Shahid
Registered Member
Posts: 47
Joined: Sun Aug 25, 2013 1:00 am

Re: Geeting Current Date in a COBOL program.

Post by Shahid »

Thanks both. I have made use of CURRENT-DATE.
Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Return to “IBM COBOL, GnuCOBOL (OpenCOBOL), OOCobol.”