sponsored links

Collapse

Announcement

Collapse
No announcement yet.

Determine difference between two times

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Determine difference between two times

    Hi,
    I have two timestamps; a beginning and an ending.
    I need to determine the elapsed time from the beginning to the ending.

    There must be an easy way of doing this but cannot put my finger on it.

    It seems that all the operation codes only allow processing on a specific portion; hours, minutes, seconds....
    Is there a way to do what I want without 30 lines of code to extract each portion and then calculate the difference?

    I thought RPGLE was suppose to be easier.
    I could convert the hours and minutes to seconds of both values and then calculate like I used to do in RPG III but that seems archaic and if anyone saw that in my code, I would be embarrassed to say the least.

    PLEASE, no FREE examples. they will not allow it. RPGLE only.

    Thanks in advance,
    Mike.
    Everyday's a school day, what grade are you in?

  • #2
    I am curious about your shop. Why would there be a restriction on using FREE? Is there some old dinosaur stopping you?

    Comment


    • #3
      What about the SUBDUR op-code?

      Comment


      • #4
        I don't fight city hall corvair61, I do what I'm told.
        I'm pushing for upgrade to current century but until then....

        Any suggestion regarding my post?
        Everyday's a school day, what grade are you in?

        Comment


        • #5
          jtaylor,
          SUBDUR requires individual operations codes; *H, *M, *S

          If I wanted to subtract 30 days (30:*D) from today or 45 minutes (45:*MN) from now, yeah, that's doable

          But not for a whole time subtracted from another whole time.
          Everyday's a school day, what grade are you in?

          Comment


          • #6
            Originally posted by redvan View Post
            jtaylor,
            SUBDUR requires individual operations codes; *H, *M, *S

            If I wanted to subtract 30 days (30:*D) from today or 45 minutes (45:*MN) from now, yeah, that's doable

            But not for a whole time subtracted from another whole time.
            Per the docs (although maybe I'm misunderstanding what you're asking):
            Calculate a duration
            The SUBDUR operation can also be used to calculate a duration between:
            1. Two dates
            2. A date and a timestamp
            3. Two times
            4. A time and a timestamp
            5. Two timestamps

            Comment


            • #7
              Originally posted by redvan View Post

              I thought RPGLE was suppose to be easier.
              It is. Period.

              Originally posted by redvan View Post
              PLEASE, no FREE examples. they will not allow it. RPGLE only.
              RetVan - any sarcasm here is aimed primarily at your employer - not you.

              1) Free-form IS RPGLE. If you want to restrict free-form uses in the responses then you need to either say "fixed form only" or at least say what "flavor" of free-form you mean.

              For example: X = Y; style free-form has been available since V5R1 - that is SEVENTEEN (17) years ago. Hardly modern so it is not really surprising that most people use it for their examples. Why would anyone code in a version older than that? It makes no sense. If you mean is what is often referred to as **Free then that is a mere EIGHT (8) years old but as far a calcs are concerned only affects the column in which you start coding.

              2) SUBDUR will calculate a duration - you just have to tell it what format the duration is in. Minutes? Seconds? If you want the interval in (say) an H:M:S type format then you must calculate the duration to the lowest level and then use math to convert the seconds to that format. There are examples out on the web. Most of us would create a subprocedure to perform that function but I'm guessing that those are probably verbotten in your shop as well.

              3) If you want to directly produce an interval then that can be done easily using embedded SQL in your RPG - but again I'm guessing that that also a no-no.

              For those of you on the list used to "kindler, gentler" responses from me - yes - I am getting old and cranky and increasingly intolerant of stupid shops that can't get out of their own way.

              Comment


              • redvan
                redvan commented
                Editing a comment
                My reply to corvair61 wasn't rude and I understood his context so I'm puzzled by your comment about sarcasm.

              • JonBoy
                JonBoy commented
                Editing a comment
                redvan I have no idea why you thought I was referring to you being sarcastic. You weren't and I wasn't. I was talking about MYSELF. I didn't want you to take anything I said as a personal criticism. Does that clarify?

            • #8
              There is a difference between free format and fixed format but that doesn't stop you from using functions.
              You can use functions in fixed format without problems.
              In this case I would use the %DIFF function.

              For example ( the example does not align to the specific columns of the D- and C-specifications. You have to ajust them yourself )
              D start_time S Z
              D time_taken S 15P 0
              C eval time_taken = %DIFF (%timestamp() : start_time : *SECONDS)

              The 3. parameter tells the function what unit it should return the period in.
              For two timestamps the valid values are: *MSECONDS, *SECONDS, *MINUTES, *HOURS, *DAYS, *MONTHS, and *YEARS

              I recommend that you take a look in the manual.

              Regards
              Peder

              Comment

              sponsored links

              Collapse

              Working...
              X