Difference between 2 dates times in Basic Script.

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

  • Difference between 2 dates times in Basic Script.

    Anyone know of a way to get the difference between 2 date/times in Basic Script? Similar to the datediff function in VBA.
    JVWhy CAD++ 2013 MR1 SP5 B&S Global Advantage.
    Optimism is the leading cause of disappointment.

  • #2
    I want you to know that I've been tempted by this challenge a few times, but it is non-trivial. If I had such an example I would surely give it to you. If every month had the same number of days, it would be simply, but you have to convert each month independently, for both dates, and then find the difference in days. The same is true for years, they are not all the same if you cross a leap year. Its not impossible, I just have not done it yet.

    Comment


    • #3
      A datetime is in fact a double, with the date in the integer part and the time in the decimals. So, you just convert your dates to double and do the subtraction, and you will get the number of days (and fractions of days) between the two:

      Code:
      Sub Main
       d1 = cdbl(dateserial(2015, 2, 1))
       d2 = cdbl(dateserial(2015, 3, 1))
       MsgBox d2-d1
      End Sub
      gives the answer 28, while

      Code:
      Sub Main
       d1 = cdbl(dateserial(2016, 2, 1))
       d2 = cdbl(dateserial(2016, 3, 1))
       MsgBox d2-d1
      End Sub
      gives 29, so it seems leap years are also handled.
      AndersI
      SW support - Hexagon Metrology Nordic AB

      Comment


      • #4
        Nice job Anders1 !! As often the case, I was looking for the more complex approach, when in fact the better solution was much simpler.

        Comment


        • #5
          I wrote this "code", just using assignments, to measure the time of exe of a prog :
          Those lines at the start :

          Code:
            ASSIGN/V2=SYSTEMTIME("HH:mm:ss")
          ASSIGN/HOUR1=ELEMENT(1,":",V2)
          ASSIGN/MINUTE1=ELEMENT(2,":",V2)
          ASSIGN/SEC1=ELEMENT(3,":",V2)
          Those lines at the end of the prog :


          Code:
           ASSIGN/V4=SYSTEMTIME("HH:mm:ss")
          ASSIGN/HOUR2=ELEMENT(1,":",V4)
          ASSIGN/MINUTE2=ELEMENT(2,":",V4)
          ASSIGN/SEC2=ELEMENT(3,":",V4)
          IF/HOUR2<HOUR1
          ASSIGN/HOUR2=HOUR2+24
          END_IF/
          ASSIGN/V5=(HOUR2-HOUR1)*3600+(MINUTE2-MINUTE1)*60+(SEC2-SEC1)
          COMMENT/OPER,NO,FULL SCREEN=NO,AUTO-CONTINUE=NO,
          "Time = "+V5+" seconds"
          It works if the prog is less than 2 days !!!!!

          For dates, it's more hard, because months are not always the same !!!!!

          Comment


          • #6
            Thank you

            Originally posted by AndersI View Post
            A datetime is in fact a double, with the date in the integer part and the time in the decimals. So, you just convert your dates to double and do the subtraction, and you will get the number of days (and fractions of days) between the two:

            Code:
            Sub Main
             d1 = cdbl(dateserial(2015, 2, 1))
             d2 = cdbl(dateserial(2015, 3, 1))
             MsgBox d2-d1
            End Sub
            gives the answer 28, while

            Code:
            Sub Main
             d1 = cdbl(dateserial(2016, 2, 1))
             d2 = cdbl(dateserial(2016, 3, 1))
             MsgBox d2-d1
            End Sub
            gives 29, so it seems leap years are also handled.
            Thank you! I'll give that a try.
            JVWhy CAD++ 2013 MR1 SP5 B&S Global Advantage.
            Optimism is the leading cause of disappointment.

            Comment


            • #7
              You can add a "runtime" output in the report header. I replaced the stats count block since I don't use it. All my reports tell me how long the execute time was on my program. It helps to be able to walk away and work on something else until the program finishes

              Comment


              • #8
                Originally posted by william View Post
                You can add a "runtime" output in the report header. I replaced the stats count block since I don't use it. All my reports tell me how long the execute time was on my program. It helps to be able to walk away and work on something else until the program finishes
                That would be very useful for us. How is this done? Thanks.

                Comment


                • #9
                  Do you still need to know how to set this up?

                  Comment


                  • MihaelR
                    MihaelR commented
                    Editing a comment
                    Hi William, if you could tell me it would really help me

                Related Topics

                Collapse

                Working...
                X