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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to conduct arthimetic operations on the current date and time

Functions

How to conduct arthimetic operations on the current date and time

by  GC1CEO  Posted    (Edited  )
First, to get the current date and time (Y2K compliant), the function name is current-date (this covers BOTH date and time), first you need to seperate it into different parts if you want to perform operations with them, for example if you wish to compare the current year to a number in storage. In your working storage section you want to define the following:

01 DATE-IN.
05 YEAR-IN PIC 99.
05 MONTH-IN PIC 99.
05 DATE-IN PIC 99.
05 HOUR-IN PIC 99.
05 MINUTE-IN PIC 99.

Take in mind, that the time is listed in Zulu time (24 hour format) so you will have to do some operations to convert it to the 12 hour format.

In the procedure division, just do:

MOVE FUNCTION CURRENT-DATE TO DATE-IN.

Since your DATE-IN is seperated into its different (and properly sized) sections in the Working Storage section, then you simply use the specific identifier you wish to conduct operations on, for example:

COMPUTE YEARS-AMT = YEAR-IN - OLD-YEAR

Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top