Menu

Function COMBINED-DATETIME

2021-12-25
2022-04-04
  • Eugenio Di Lorenzo

    I wonder what the function can be used for.
    Is there anyone who can explain it?

     
    • Vincent (Bryan) Coen

      argument-1 *
      Must be in integer date form. For details, see Integer date form
      https://www.ibm.com/docs/en/SS6SG3_6.3.0/lr/ref/rlinfspecg.html#INFFORM__int_date.
      A value in integer date form is a positive integer that represents a
      number of days succeeding 31 December 1600, in the Gregorian
      calendar. It is based on a starting date of Monday, 1 January 1601
      and integer date 1 represents Monday, 1 January 1601.
      The |INTDATE| compiler option affects the starting date for the
      integer date functions. For details, see INTDATE
      https://www.ibm.com/docs/en/SS6SG3_6.3.0/pg/ui/up0039.html.
      argument-2*
      Must be in standard numeric time form. For details, see Standard
      numeric time form
      https://www.ibm.com/docs/en/SS6SG3_6.3.0/lr/ref/rlinfspecg.html#INFFORM__stand_numeric.
      A value in standard numeric time form is a numeric value
      representing seconds past midnight.

      The returned value is determined by arithmetic expression argument-1 +
      (argument-2/100000). The date occupies the integer part of the returned
      value and the time is represented in the fractional part of the returned
      value.

      Example
      

      Given the integer date form value "143951", which represents the date 15
      February 1995, and the standard numeric time form value
      "18867.812479168304", which represents the time "05:14:27.812479168304",
      the returned value would be exactly "143951.1886781247" with the
      |ARITH(COMPAT)| compiler option in effect and exactly
      "143951.18867812479168304" with the|ARITH(EXTEND)| compiler option in
      effect.

      On 25/12/2021 19:08, Eugenio Di Lorenzo wrote:

      I wonder what the function can be used for.
      Is there anyone who can explain it?

       
  • Mickey White

    Mickey White - 2021-12-25

    Well, I used just regular date time string for generating sudo-random numbers. But here is a quick write up of this on the IBM Cobol LR manual:
    Support for industry standard date and time
    formats
    New date and time intrinsic functions are introduced
    that support encoding and decoding of date and time
    information to and from formats specified in ISO
    8601, and that support encoding and decoding date
    and time information to and from integers that are
    suitable for arithmetic. These new intrinsic functions
    are:
    • COMBINED-DATETIME
    • FORMATTED-CURRENT-DATE
    • FORMATTED-DATE
    • FORMATTED-DATETIME
    • FORMATTED-TIME
    • INTEGER-OF-FORMATTED-DATE
    • SECONDS-FROM-FORMATTED-TIME
    • SECONDS-PAST-MIDNIGHT
    • TEST-DATE-YYYYMMDD
    • TEST-DAY-YYYYDDD
    • TEST-FORMATTED-DATETIME

    And Merry Christmas to you Eugenio.

     
  • Eugenio Di Lorenzo

    very many thanks and Merry Christmas to you both , but my question was different.
    I don't ask for an explanation of how it works and how it is used but ... for what purpose the function can be used. Which goal allows you to achieve. This is what I was wondering.
    perhaps with an example of a situation where this function is used.

    Please note.
    In a different and previous post I asked if anyone knows the simplest way to calculate the number of seconds between two times, even on different dates.
    see https://sourceforge.net/p/gnucobol/discussion/help/thread/37a318675e/#e73e
    Example number of seconds between 23:13:12 on 25.12.20221 and 02:54:27 on 26.12.2021.
    I was wondering if I could use COMBINED-DATETIME to calculate the difference between two Dates and Times ?

     

    Last edit: Eugenio Di Lorenzo 2021-12-25
    • Mickey White

      Mickey White - 2021-12-27

      I see what you mean, Eugenio, there is not a good explanation of what combined-datetime really is supposed to do. Is it just to concatenate the two arguments?

      Well anyway, the only process that I know of that will calculate the total seconds between dates and times are in the IBM Mainframe Environment z/OS Language Environment callable services. There is a CEESECS routine that works very well .

      As far as I could say about a COBOL solution would be to get the number of days between the two dates ( the integers of the dates difference) and multiply that by the number of seconds in a 24 hour day, and then add the number of seconds that have passed since midnight of both of the dates used. I would think calculating the number of days using integer-of-date will account for all of the possible leap year days.

       

      Last edit: Mickey White 2021-12-27
      • Anonymous

        Anonymous - 2021-12-27

        I wrote a lot of the CEE services in COBOL
        CEESECS expects a concatenated date-time.
        Using a date-time string this is how I recollect it works.

        If I remember correctly CEESECS calls CEEDAYS for a Lillian date (using the input date)
        The Lillian date is the number of days since Oct/14/1582.

        CEESECS returns the number of seconds since Oct/14/1582 at midnight (using the calculated Lillian date and the input time)

        The result is the number of seconds from the input epoch data-time.

        Call CEESECS with the other between date.

        Subtract one from the other - voila the elapsed seconds of the 2 dates.

         
        • Simon Sobisch

          Simon Sobisch - 2022-04-04

          Whoever posted that, possibly @zosralph, would you make the "lot of CEE services in COBOL" that you've wrote available under a free license?

          We could include those possibly in "extras" (so with a COB_PRE_LOAD you'd get access to them via CALL) or at least make it available under "contrib/tools" for the same purpose (in which case full copyright can be retained and there are more free licenses to choose of).

           
    • Mickey White

      Mickey White - 2022-03-23

      Eugenio, Here is a program that should calculate the Seconds between two date and time sets. It is command line enter and display. Could be converted to a subroutine or even using a File as input....
      I ran it on both Windows 10 and Ubuntu . the answer to your above question is 13275 seconds
      D:\Old Hard Drive\Documents\Computer Stuff>secondsbetweendatetime 20211225 231312 20211226 025427
      +0000000000000000000000000013275

      attached is the program secondsbetweendatetime.cbl

       
      • Eugenio Di Lorenzo

        hello Mickey and thanks for your reply.
        therefore the combined-datetime function is not useful for this purpose. This is a pity.
        your solution is therefore very good.
        now, to complete the requirement, there would only be the need to convert the total number of seconds into a ccyy: mm: dd hh: mm: ss format.
        is there a standard cobol function for this?

         
        • Mickey White

          Mickey White - 2022-04-02

          I know of no function. What would the date start point be? Like if say 399939393 seconds is 2 years 2 months 10 days 2 hours 10 seconds, what would the date be?
          0002:02:10:02:10 (year 0002) ?

           
          • Eugenio Di Lorenzo

            Obviously it is not a date but only the time elapsed between two dates.
            and it is shown in a different form (combining DATE and TIME) with respect to the total of seconds.

            This could be a possibility for improvement when the next ISO COBOL standard will be prepared and issued.
            To have standard FUNCTIONS available for calculating the elapsed date and time.
            The FUNCTIONS that already exist, apparently, allow the calculation of the elapsed elapsed between two dates but not between two times nor date and time together.

             

            Last edit: Eugenio Di Lorenzo 2022-04-04
            • Simon Sobisch

              Simon Sobisch - 2022-04-04

              There was ongoing work in the current iteration of the COBOL standard for new USAGEs: DATE, TIME, DATETIME. Those were dropped because of open issues and time constraints, but they are on the plate for the next iteration.
              If this works out you can ACCEPT datime-value FROM DATETIME two times, then just SUBTRACT those to get the result which you can then use with the intrinsic functions to get out a print format as you like (or just DISPLAY it and get the default output format, whatever that will be).

               
  • Chuck Haatvedt

    Chuck Haatvedt - 2022-04-02

    perhaps this is a bit off topic, but I'll reply as it may be related. I've used this to evaluate the performance of some memory caching via the virtual file handling functions that I've been working on. I needed to check the elapsed time used to create, read and write data to a virtual file. So I wrote a C function which calls the Windows ftime function. On LINUX perhaps the gettimeofday(2) could be used instead. I'll leave that to the Linux folks as that is outside of my experience base.

    as part of my work on creating a windows DLL to emulate the FUJITSU CBL_xxxx_VFILE routines I added two functions as follows.

    CWH_START_TIME();     
    CWH_TIME_DIFF(void *a)
    

    so in cobol you would call CWH_START_TIME with no parameters to start the timer interval.

    then call CWH_TIME_DIFF using msecs , where msecs is an integer BINARY-LONG which will contain the number of milliseconds between the two CWH time functions. I found it to be very useful,

    I suspect that it would be fairly easy to add them to the GNUCOBOL compiler itself if there is an interest.

    here is the C code...

    //
    // =====> this function just gets the starting timeb data
    //        it will be used by a subsequent call to
    //        CWH_TIME_DIFF
    //
    
    int CWH_START_TIME()
    {
       ftime(&t_start);
       got_start_time = TRUE;
       return(0);
    }
    
    
    //
    // =====> this function just gets the current timeb data
    //        and uses it to calculate the difference in
    //        milliseconds.
    //
    
    int CWH_TIME_DIFF(void *a)
    {
       int     *ptr_int;
    
       ptr_int     = a;
    
       if (got_start_time == FALSE)
       {
           *ptr_int    = 0;
           return(MISSING_START_TIME);
       }
    
       ftime(&t_current);
    
       *ptr_int = (int) (1000.0 * (t_current.time - t_start.time)
         + (t_current.millitm - t_start.millitm));
       return(0);
    }
    

    Also creating a function in C to return something like a DB2 timestamp might be fairly easy to do with the caveat that getting the microseconds might prove to be difficult. I would need to investigate what time functions are available.

     

    Last edit: Chuck Haatvedt 2022-04-02

Anonymous
Anonymous

Add attachments
Cancel