MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Date and Time (Cobol)

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
luis_a_roman
Beginner


Joined: 17 Jul 2003
Posts: 3
Topics: 3

PostPosted: Mon Aug 18, 2003 8:36 am    Post subject: Date and Time (Cobol) Reply with quote

How could I retrieve the current date and time in a cobol program? I used the current-date and current-time register and was not able to get them. Could someone help me with a code example?

Thank you.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12376
Topics: 75
Location: San Jose

PostPosted: Mon Aug 18, 2003 9:47 am    Post subject: Reply with quote

The latest ENTERPRISE COBOL has an intrinsic funtion CURRENT-DATE which returns a 21-character alphanumeric value that represents the calendar date, time of day, and time differential from Greenwich Mean Time provided by the system on which the function is evaluated.

Check here for a detailed explanation of the function current-date

http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/IGY3LR10/7.1.9?DT=20020920180651

If your shop still happens to have VS COBOL II , then look at example 2 on date. check this link for a detailed explanation of

DATE, DAY, DAY-OF-WEEK, and TIME


And here is an ENTERPRISE COBOL example of getting the date and time

Code:

IDENTIFICATION DIVISION.                                     
PROGRAM-ID.    DATETIME                                       
DATE-COMPILED.                                               
ENVIRONMENT DIVISION.                                       
CONFIGURATION SECTION.                                       
INPUT-OUTPUT SECTION.                                       
FILE-CONTROL.                                               
DATA DIVISION.                                               
FILE SECTION.                                               
WORKING-STORAGE SECTION.                                     
                                                             
01  DATE-TODAY.                                             
    05 CCYY                     PIC X(04).                   
    05 FILLER                   PIC X(01) VALUE '-'.         
    05 MM                       PIC X(02).                   
    05 FILLER                   PIC X(01) VALUE '-'.         
    05 DD                       PIC X(02).                   
    05 HH                       PIC X(02).                   
    05 FILLER                   PIC X(01) VALUE ':'.         
    05 MIN                      PIC X(02).                   
    05 FILLER                   PIC X(01) VALUE ':'.         
    05 SEC                      PIC X(02).                   
                                                             
PROCEDURE DIVISION.                                         
                                                             
     MOVE FUNCTION CURRENT-DATE(1:4)  TO CCYY               
     MOVE FUNCTION CURRENT-DATE(5:2)  TO MM                 
     MOVE FUNCTION CURRENT-DATE(7:2)  TO DD                 
     MOVE FUNCTION CURRENT-DATE(9:2)  TO HH                 
     MOVE FUNCTION CURRENT-DATE(11:2) TO MIN                 
     MOVE FUNCTION CURRENT-DATE(13:2) TO SEC                 
                                                             
                                                             
     DISPLAY 'THE DATE TODAY IS :' DATE-TODAY(1:10)         
     DISPLAY 'THE TIME NOW IS   :' DATE-TODAY(11:8)         
                                                             
     GOBACK.                                                 

The result is :
Code:

THE DATE TODAY IS :2003-08-18 
THE TIME NOW IS   :10:44:57   


Here is an example of VS COBOL II

Code:

IDENTIFICATION DIVISION.                         
PROGRAM-ID.    DATETIME                         
DATE-COMPILED.                                   
ENVIRONMENT DIVISION.                           
DATA DIVISION.                                   
WORKING-STORAGE SECTION.                         
                                                 
01 CURRENT-DATE        PIC 9(06).               
01 CURRENT-TIME        PIC 9(08).               
                                                 
PROCEDURE DIVISION.                             
                                                 
    ACCEPT CURRENT-DATE FROM DATE               
    ACCEPT CURRENT-TIME FROM TIME               
                                                 
    DISPLAY 'THE DATE TODAY IS :' CURRENT-DATE   
    DISPLAY 'THE TIME NOW   IS :' CURRENT-TIME   
                                                 
    GOBACK.
                                     


The result is :

Code:

THE DATE TODAY IS :030818 
THE TIME NOW   IS :10454163


Hope this helps...

cheers

kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group