Date: 02-16-2022
Return to Index
created by gbSnippets
'The equations for the Astronomical Day (also called the Julian Date)
'of a date can be used to make the calculation.
'Primary Code:
'Credit: MSDN http://support.microsoft.com/kb/109451
'To get the days between two dates, simply subtract their Astronomical Days
Function AstroDay(year As Long, month As Long, day As Long) As Long
Dim y As Double
y = year + (month - 2.85) / 12
AstroDay = Int(Int(Int(367 * y) - 1.75 * Int(y) + day) -0.75 * Int(0.01 * y)) + 1721119
End Function
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Label, hDlg, 130,"9-12-1951", 50,20,100,20
Control Add Label, hDlg, 135,"9-12-2009", 50,50,100,20
Control Add Button, hDlg, 140,"Push", 50,80,100,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
If CB.Msg = %WM_Command AND CB.Ctl = 140 AND CB.Ctlmsg = %BN_Clicked Then
Local Day1 As Long, Day2 as Long, y As Long, m As Long, d As Long, temp$
'1st date
Control Get Text hDlg, 130 To temp$
y = Val(Parse$(temp$, "-", 3))
m = Val(Parse$(temp$, "-", 1))
d = Val(Parse$(temp$, "-", 2))
Day1 = AstroDay(y, m, d)
'2nd date
Control Get Text hDlg, 135 To temp$
y = Val(Parse$(temp$, "-", 3))
m = Val(Parse$(temp$, "-", 1))
d = Val(Parse$(temp$, "-", 2))
Day2 = AstroDay(y, m, d)
MsgBox Str$(Day2 - Day1), %MB_OK, "Days Between Dates"
End If
End Function
Function AstroDay(year As Long, month As Long, day As Long) As Long
Dim y As Double
y = year + (month - 2.85) / 12
AstroDay = Int(Int(Int(367 * y) - 1.75 * Int(y) + day) -0.75 * Int(0.01 * y)) + 1721119
End Function
'gbs_00283
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm