05-20-2024, 04:22 PM
For date difference calculations why not convert to Julian and get the difference?
Code: (Select All)
Start:
Input "Date1: ", d1$
If d1$ = "" Then System
Input "Date2: ", d2$
Print "Difference in days: "; Julian#(d2$) - Julian#(d1$)
Print: Print: Print
GoTo Start
Function Julian# (from$)
'Gives # of days since Monday, January 1, 4713 BC
'accepts xx-xx-xxxx OR xx/xx/xxxx OR xx-xx-xx OR xx/xx/xx
'from$ must be either 8 or 10 characters
If Len(from$) <> 8 And Len(from$) <> 10 Then Julian# = 0: Exit Function
'must be xx-xx or xx/xx format
If Mid$(from$, 3, 1) <> "-" And Mid$(from$, 3, 1) <> "/" Then Julian# = 0: Exit Function
If Mid$(from$, 6, 1) <> "-" And Mid$(from$, 6, 1) <> "/" Then Julian# = 0: Exit Function
Month% = Val(Mid$(from$, 1, 2))
Day% = Val(Mid$(from$, 4, 2))
If Len(from$) = 10 Then
Year% = Val(Right$(from$, 4))
ElseIf Len(from$) = 8 Then
Year% = Val("20" + Right$(from$, 2))
End If
Select Case Month%
Case Is >= 3
Month% = Month% - 3
Case Is <= 2
Month% = Month% + 9
Year% = Year% - 1
End Select
A# = 146097# * Fix(Fix(Year% / 100) / 4)
B# = Fix(1461# * (Year% Mod 100) / 4)
C# = Fix((153# * Month% + 2) / 5) + Day% + 1721119
Julian# = A# + B# + C#
End Function