COBOL

Expand all | Collapse all

Questions about new date/time intrinsic functions

  • 1.  Questions about new date/time intrinsic functions

    Posted Mon June 14, 2021 01:37 PM
    Edited by Frank Swarbrick Tue June 15, 2021 01:17 PM
    Given the following:
     01  dateint                     pic s9(7) comp-3.
    [...]
         compute dateint = integer-of-formatted-date ('YYYYMMDD'   
                                                      '20210614')  
         display dateint                                           
         display formatted-date('YYYY-MM-DD' dateint)              
                                                                   
         compute dateint = integer-of-date(20210614)               
         display dateint                                           
         display formatted-date('YYYY-MM-DD' dateint)              ​

    The integer-of-formatted-date function seems not to give the correct result.  Or am I doing something wrong?
    +00153567 
    2003-03-28​

    The integer-of-date function is correct.
    +00160220  
    2021-06-14 ​


    Also a question about formatted-current-date.  These two work fine:

         display formatted-current-date('YYYYMMDDThhmmss.ss+hhmm')
         display formatted-current-date('YYYY-MM-DDThh:mm:ss.sss')


    These two don't compile:

         display formatted-current-date('YYYYMMDD')  
         display formatted-current-date('YYYY-MM-DD')
    
        52  IGYPA3382-S   The specified date, time, or combined date and time       
                          format string argument-1 "'YYYYMMDD'" is not a valid      
                          input for "ALPHANUMERIC FUNCTION FORMATTED-CURRENT-DATE". 
                          The statement was discarded.                              
        53  IGYPA3382-S   The specified date, time, or combined date and time       
                          format string argument-1 "'YYYY-MM-DD'" is not a valid    
                          input for "ALPHANUMERIC FUNCTION FORMATTED-CURRENT-DATE". 
                          The statement was discarded.                              

    The messages seem to indicate that a "date only" format string is allowed, but its not accepting the ones I tried here.



    ------------------------------
    Frank Swarbrick
    ------------------------------


  • 2.  RE: Questions about new date/time intrinsic functions

    Posted Mon June 21, 2021 01:49 PM
    Hi, Frank.  Based on your reported results, it appears that you are running the compiles calling the integer-of-formatted-date function with the INTDATE(LILIAN) compiler option specified.  For an explanation of how the INTDATE(ANSI|LILIAN) option affects the date and time intrinsic function calculations, please refer to the section titled "Using date callable services" in the Enterprise COBOL Programming Guide,  Here's a partial summary for you.

    Both the COBOL date intrinsic functions and the Language Environment date callable services are based
    on the Gregorian calendar. However, the starting dates can differ depending on the setting of the INTDATE
    compiler option.

    When INTDATE(LILIAN) is in effect, COBOL uses October 15, 1582 as day 1. Language Environment
    always uses October 15, 1582 as day 1. If you use INTDATE(LILIAN), you get equivalent results from
    COBOL intrinsic functions and Language Environment date callable services.

    When the default setting of INTDATE(ANSI) is in effect, COBOL uses January 1, 1601 as day 1.

    To answer your second question about the use of the formatted-current-date function, the Enterprise COBOL Language Reference states the following:

    argument-1
    Must be a national, a UTF-8, or an alphanumeric literal.
    The content of argument-1 must be a combined date and time format. For details, see "Date and time
    formats" on page 468.

    Please let me know if I have not addressed your questions fully.

    ------------------------------
    Greg Doolittle
    ------------------------------



  • 3.  RE: Questions about new date/time intrinsic functions

    Posted Tue June 22, 2021 06:03 PM
    Hi Greg,
    Perhaps I am being obtuse, but it seems to me that regardless of the setting of INTDATE, shouldn't the result of
    integer-of-formatted-date('YYYYMMDD' '20210614')​
    and
    integer-of-date(20210614)​

    be the same number?  The number itself may be different, depending on the INTDATE option, but within the same compiled program should they not be the same?  It looks to me like integer-of-formatted-date is always calculated as if INTDATE(ANSI) was set, whereas integer-of-date respects the INTDATE setting.

    As for the formatted-current-date function, that is disappointing, but I see that's how it's stated in the standard as well.  Oh well!



    ------------------------------
    Frank Swarbrick
    ------------------------------



  • 4.  RE: Questions about new date/time intrinsic functions

    Posted Wed June 23, 2021 09:29 AM

    Hi Frank,

     

    No you're not being obtuse.  You are correct that the result of
    integer-of-formatted-date('YYYYMMDD' '20210614') and
    integer-of-date(20210614), should be the same, regardless of the setting of INTDATE.  The result returned from integer-of-formatted-date is always calculated as if INTDATE(ANSI) was set, whereas integer-of-date, as well as all of the other new date/time intrinsic functions we implemented that take an integer date as an INPUT, do respect the INTDATE setting.  This is a bug and we are going to fix it.  Thank you for reporting this to us.

     


    Best regards,

    Gregory D. Doolittle

    Enterprise COBOL Front-End Development
    IBM z Systems Software, IBM Systems Unit
    Phone: 720-395-9970
    Cell: 607-429-8066
    Internet: gregdd@us.ibm.com

    ++++++++++++++++++++++++++++++++

     

     

     

     






  • 5.  RE: Questions about new date/time intrinsic functions

    Posted Wed June 23, 2021 01:16 PM
    Great!  Thanks, Greg!

    ------------------------------
    Frank Swarbrick
    ------------------------------



  • 6.  RE: Questions about new date/time intrinsic functions

    Posted Fri July 19, 2024 09:57 AM

    I have the same issue with using FORMATTED-CURRENT-DATE ;

                    MOVE FUNCTION FORMATTED-CURRENT-DATE ('YYYYDDDHHMMSS') TO       
                                                                                    
    IGYPA3382-S THE SPECIFIED DATE, TIME, OR COMBINED DATE AND TIME FORMAT STRING   
                ARGUMENT-1 "'YYYYDDDHHMMSS'" IS NOT A VALID INPUT FOR "ALPHANUMERIC 
                FUNCTION FORMATTED-CURRENT-DATE".  THE STATEMENT WAS DISCARDED.     
                                                                                    
                         W1000-YYYYDDDHHMMSS-FORMAT.                                



    ------------------------------
    Raymond Baxter
    ------------------------------



  • 7.  RE: Questions about new date/time intrinsic functions

    Posted Mon July 22, 2024 07:06 AM

    Hi Raymond,

    In your case, the format should be 'YYYYDDDThhmmss' to avoid the IGYPA3382-S message. See Format of arguments and return values for date and time intrinsic functions regarding combining basic date and time formats.

    Bernie



    ------------------------------
    Bernie Rataj
    Technical Support Professional
    IBM Canada Ltd.
    Markham

    https://www.ibm.com/products/cobol-compiler-zos
    https://www.ibm.com/products/pli-compiler-zos
    ------------------------------



  • 8.  RE: Questions about new date/time intrinsic functions

    Posted Mon July 22, 2024 11:32 AM

    Note also that you can only combine "basic" dates and times, and "extended" dates and times. So 'YYYY-DDDThh.mm.ss' doesn't work because it's an extended date with a basic time.



    ------------------------------
    Bernie Rataj
    Technical Support Professional
    IBM Canada Ltd.
    Markham

    https://www.ibm.com/products/cobol-compiler-zos
    https://www.ibm.com/products/pli-compiler-zos
    ------------------------------



  • 9.  RE: Questions about new date/time intrinsic functions

    Posted Tue July 23, 2024 08:06 AM

    Out of curiosity, why does COBOL not use a dash (-) for the date and time separator the way a Db2 Timestamp does?  This smacks of COBOL II using the start of "modern" dates as 1 January 1601 rather than the Gregorian date 15 October 1582.



    ------------------------------
    Jon Butler
    ------------------------------



  • 10.  RE: Questions about new date/time intrinsic functions

    Posted Tue July 23, 2024 09:51 AM

    Hi Jon,

    You can produce ISO-8601 style date/time strings with dashes between the date components from for example FUNCTION COMBINED-DATETIME. The number/capability of date functions has been increased of late.

    The INTDATE compiler option can be used for either the default ANSI 85 COBOL Standard date origin of 1 January 1601 or the LILIAN of 15 October 1582 (also used by LE). Given how long COBOL programs are usually around, ANSI dating might still be an important consideration for some programs.

    Bernie 



    ------------------------------
    Bernie Rataj
    Technical Support Professional
    IBM Canada Ltd.
    Markham

    https://www.ibm.com/products/cobol-compiler-zos
    https://www.ibm.com/products/pli-compiler-zos
    ------------------------------



  • 11.  RE: Questions about new date/time intrinsic functions
    Best Answer

    Posted Mon June 28, 2021 12:17 PM
    For reference, APAR PH38499 has been opened to address this issue.  (The text of the APAR should be published externally within the next couple days.)

    ------------------------------
    Terri Menchak
    ------------------------------



  • 12.  RE: Questions about new date/time intrinsic functions

    Posted Tue August 13, 2024 12:26 PM

    It appears that function COMBINED-DATETIME may also not be respecting INTDATE(LILIAN) correctly.  Here are results of a program that uses INTEGER-OF-FORMATTED-DATE and SECONDS-FROM-FORMATTED-TIME as inputs into COMBINED-DATETIME, and then uses FORMATTED-DATETIME to a timestamp string back.  It works as expected for INTDATE(ANSI), but gets unexpected results for INTDATE(LILIAN).

    INTDATE(ANSI)
    1995-02-15T05:14:27
    000143951000018867 
    000143951188670000 
    1995-02-15T05:14:27
     
    INTDATE(LILIAN)
    1995-02-15T05:14:27
    000150604000018867 
    000143951188670000 
    1976-11-28T05:14:27

    Here is the test program.

     identification division.                                   
     function-id. fraction-part as 'FRACTPT' is prototype.      
     data division.                                             
     linkage section.                                           
     01  arg                         pic 9(9)v9(9) comp.        
     01  result                      pic v9(9) comp.            
     procedure division using value arg returning result.       
     end function fraction-part.                                
                                                                
     identification division.                                   
     program-id. timestmp.                                      
                                                                
     environment division.                                      
     configuration section.                                     
     repository.                                                
         function fraction-part                                 
         function all intrinsic.                                
                                                                
     data division.                                             
     working-storage section.                                   
     01  timestamp                   pic x(19) value            
         "1995-02-15T05:14:27".                                 
     01  dt-date                     pic 9(9) comp.             
     01  dt-time                     pic 9(9) comp.             
     01  combined-dttm               pic 9(9)v9(9) comp.        
                                                                
     procedure division.                                        
         display timestamp                                      
                                                                
         compute dt-date = integer-of-formatted-date(           
                             "YYYY-MM-DDThh:mm:ss" timestamp)   
         compute dt-time = function seconds-from-formatted-time(
                             "YYYY-MM-DDThh:mm:ss" timestamp)   
         compute combined-dttm = combined-datetime(dt-date dt-time) 
                                                                    
         display dt-date dt-time                                    
         display combined-dttm                                      
                                                                    
         move formatted-datetime(                                   
                "YYYY-MM-DDThh:mm:ss" integer-part(combined-dttm)   
                fraction-part(combined-dttm) * 100000) to timestamp 
                                                                    
         display timestamp                                          
                                                                    
         goback.                                                    
                                                                    
     end program timestmp.                                          
                                                                    
     identification division.                                       
     function-id. fraction-part as 'FRACTPT'.                       
     data division.                                                 
     linkage section.                                               
     01  arg                         pic 9(9)v9(9) comp.            
     01  result                      pic v9(9) comp.                
     procedure division using value arg returning result.           
    *    compute result = arg - function integer-part (arg)         
         move arg to result                                         
         goback.                                                    
     end function fraction-part.                                    
    



    ------------------------------
    Frank Swarbrick
    ------------------------------



  • 13.  RE: Questions about new date/time intrinsic functions

    Posted Tue August 13, 2024 02:10 PM

    Hi Frank.  Thanks for bringing this to our attention.  As a developer of the Date/Time intrinsic functions, I will open an internal defect for this problem and make sure it gets resolved in the current release and then rolled back to the other COBOL compiler releases with this function, that are still in service (V6.4, V6.3).



    ------------------------------
    Greg Doolittle
    Greg
    ------------------------------