Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Date functions
#32
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
Reply


Messages In This Thread
Date functions - by dritter - 03-04-2024, 05:49 AM
RE: Date functions - by Pete - 03-04-2024, 06:43 AM
RE: Date functions - by Dimster - 03-04-2024, 03:04 PM
RE: Date functions - by mdijkens - 03-04-2024, 04:00 PM
RE: Date functions - by Dimster - 03-04-2024, 04:43 PM
RE: Date functions - by SMcNeill - 03-04-2024, 05:51 PM
RE: Date functions - by Kernelpanic - 03-04-2024, 06:12 PM
RE: Date functions - by mdijkens - 03-04-2024, 06:46 PM
RE: Date functions - by madscijr - 03-05-2024, 07:18 PM
RE: Date functions - by Kernelpanic - 03-05-2024, 10:52 PM
RE: Date functions - by madscijr - 03-05-2024, 11:15 PM
RE: Date functions - by bplus - 03-04-2024, 06:16 PM
RE: Date functions - by Kernelpanic - 03-04-2024, 06:19 PM
RE: Date functions - by Pete - 03-04-2024, 06:43 PM
RE: Date functions - by Kernelpanic - 03-05-2024, 11:13 PM
RE: Date functions - by madscijr - 03-05-2024, 11:28 PM
RE: Date functions - by mdijkens - 03-06-2024, 07:47 AM
RE: Date functions - by Kernelpanic - 03-05-2024, 11:27 PM
RE: Date functions - by Kernelpanic - 03-05-2024, 11:48 PM
RE: Date functions - by SMcNeill - 03-06-2024, 12:23 AM
RE: Date functions - by SpriggsySpriggs - 03-06-2024, 12:24 PM
RE: Date functions - by Kernelpanic - 03-07-2024, 11:17 PM
RE: Date functions - by mdijkens - 03-08-2024, 08:03 AM
RE: Date functions - by SMcNeill - 03-07-2024, 11:29 PM
RE: Date functions - by Kernelpanic - 03-07-2024, 11:41 PM
RE: Date functions - by SpriggsySpriggs - 03-08-2024, 12:48 PM
RE: Date functions - by Kernelpanic - 03-08-2024, 03:20 PM
RE: Date functions - by mdijkens - 03-08-2024, 04:06 PM
RE: Date functions - by bplus - 03-08-2024, 04:48 PM
RE: Date functions - by mdijkens - 03-08-2024, 05:01 PM
RE: Date functions - by Kernelpanic - 03-08-2024, 09:30 PM
RE: Date functions - by dano - 05-20-2024, 04:22 PM



Users browsing this thread: 3 Guest(s)