× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: New date handling functions in ILE/COBOL
  • From: Finucci Domenico <finucci@xxxxxxxxxxxx>
  • Date: Thu, 27 Jan 2000 15:13:15 +0100

Try this. 
Regards
Domenico  <<UDTC.TXT>> 

       IDENTIFICATION DIVISION.
       PROGRAM-ID.    UDATECALC.
       AUTHOR.        DomenicoFinucci.
       DATE-WRITTEN.  22/11/1999.
      * ----------------------------------------------------------
      * Test funzioni data
      * This program shows new ILE functions related to date handling.
      *  Upload to a source member type CBLLE and compile with PDM,
      * opz. 14. Be shure that %  (percent) sign is correctly
      * translated.
      *  D. Finucci, 23/Nov./1999.
      * --------------------------------------------------------
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SOURCE-COMPUTER. IBM-S36.
       OBJECT-COMPUTER. IBM-AS400.
       SPECIAL-NAMES. REQUESTOR     IS CONSOLE
                      DECIMAL-POINT IS COMMA
                      FORMAT DATE IS "%y/%m/%d"
                      LOCAL-DATA    IS AREA-LOCALE.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
      *
       DATA DIVISION.
       FILE SECTION.
       WORKING-STORAGE SECTION.
       77 w-curdate     format date "%y%m%d".
       77 w-futurdate   format date "%y%m%d" value "971031".
       77 w-DURATA      PIC S9(5).
       77 w-char        PIC x(5) .
       77 w-curdate1    format date "%Y%m%d".
       77 w-futurdate1  format date "%Y%m%d" value "19971031".
       LINKAGE SECTION.
      ** ----------------------------------------------------
       PROCEDURE DIVISION.
       main.
      ** 1. year with two digits
           MOVE FUNCTION CURRENT-DATE(3:8) TO w-curdate
           COMPUTE W-DURATA =
           FUNCTION FIND-DURATION (W-futurdate W-curdate days).
           display "(1) " w-curdate " - " w-futurdate
                        " = " w-DURATA " days ".
      ** 2. year with four digits
           MOVE FUNCTION CURRENT-DATE(1:8) TO w-curdate1
           COMPUTE W-DURATA =
           FUNCTION FIND-DURATION (W-futurdate1 W-curdate1 days).
           display "(2) " w-curdate1 " - " w-futurdate1
                        " = " w-DURATA " days ".
      ** 3. add days to a date
           MOVE FUNCTION CURRENT-DATE(1:8) TO w-curdate1
           move FUNCTION ADD-DURATION (W-curdate1  YEARS 2 DAYS 29 )
           to w-futurdate1.
           display "(3) " w-curdate1 " + 2 years and 29 days is  "
                        w-futurdate1.
      ** 4.: add days to a date
           MOVE FUNCTION CURRENT-DATE(1:8) TO w-curdate1
           move FUNCTION ADD-DURATION
                (W-curdate1  YEARS 2 MONTHS 2 DAYS 19 )
           to w-futurdate1.
           display "(4) " w-curdate1
                        " + 2 years, 2 months and 19 days is "
                        w-futurdate1.
      ** 5. difference between dates
           MOVE FUNCTION CURRENT-DATE(1:8) TO w-curdate1
           move FUNCTION SUBTRACT-DURATION
                (W-curdate1  YEARS 102 MONTHS 5 DAYS 38 )
           to w-futurdate1.
           display "(5) " w-curdate1
                        " - 102 years, 5 months  and 38 days = "
                        w-futurdate1.

      ** 6.: extract values from date
           MOVE FUNCTION CURRENT-DATE(1:8) TO w-curdate1
           COMPUTE w-durata  =
                      FUNCTION EXTRACT-DATE-TIME (w-curdate1  MONTHS).
           display "(6-1) " " month of date "
                   w-curdate1 ": " W-durata
           MOVE FUNCTION CURRENT-DATE(1:8) TO w-curdate1

           COMPUTE w-durata  =
                      FUNCTION EXTRACT-DATE-TIME (w-curdate1 '%d').
           display "(6-2) " " days of date "
                   w-curdate1 ": " W-durata

           MOVE FUNCTION CURRENT-DATE(1:8) TO w-curdate1
           MOVE FUNCTION
                    EXTRACT-DATE-TIME (w-curdate1 '%m/%d') to w-char .
           display "(6-3) " "gg/mm of date "
                   w-curdate1 ": " w-char.
           GOBACK.

As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.