Post Reply 
days-between-dates Solver equation for 17b
10-05-2018, 04:19 PM (This post was last modified: 10-07-2018 06:37 PM by Don Shepherd.)
Post: #1
days-between-dates Solver equation for 17b
Although a Solver equation for days-between-dates on the 17b series is unnecessary because that function is included in the Time menu, I thought it would be interesting to write a Solver equation for it anyhow. This equation is based upon the DBD algorithm found here:

https://alcor.concordia.ca/~gpkatch/gdat...rithm.html

Katie Wasserman made me aware of this algorithm many years ago.

To determine the number of days between two dates, you calculate the day number for each date and then subtract. In a programming language that supports subroutines, it would be easy to calculate the number of days difference. The 17b solver, however, does not support subroutines.

I figured out a way to use the sigma function to make up for this deficiency; it loops two times, the first loop calculating the day number of the earlier date (DT1) and then calculating the day number of the later date (DT2) during the second loop. Subtraction of the two is achieved by using variable B to multiply the result of the first loop by -1 and the result of the second loop by 1. The resulting sum yields the days between the two dates.

The solver equation works fine on the 17b and 17bii. It "might" work on the 17bii+ because it does not modify menu variables, but I wouldn't guarantee it will work on the +.

This is an interesting exercise in using a loop as a substitute for a subroutine.

Format of DT1 and DT2 is mm.ddyyyy

Code:

DBD=0xL(A:DT1)xL(B:-1)+

sigma(I:1:2:1:

  0xL(D:IP(100xFP(G(A)))) x
    L(M:MOD(IP(G(A))+9:12)) x
    L(Y:1E4xFP(G(A)x100)-IDIV(G(M):10)) +

          (365xG(Y)+IDIV(G(Y):4)
          -IDIV(G(Y):100)+IDIV(G(Y):400)
          +IDIV(G(M)x306+5:10)+G(D)-1)

           xG(B)

           +0xL(A:DT2)xL(B:1)

      )
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
days-between-dates Solver equation for 17b - Don Shepherd - 10-05-2018 04:19 PM



User(s) browsing this thread: 2 Guest(s)