A
Al
This code works but is very slow. It loops through the Julian Dates in a
table, converts them to Gregorian Dates, and then updates an empty field in
the same table.
The table is a temporary table that is generated through a prior query then
updated using this Julian date function. I am trying to set up a custom
reporting feature from a Pervasive SQL Server ODBC connection where the dates
are stored as Julian dates and then use the converted dates to link back to
dates in another database to gather the data needed for the report.
Below is my working code that converts 13,000 records in about 2 minutes,
which I feel is much too slow. There has to be a better way to do this.
Public Function SampDCal()
'CONVERTS JULIAN DATE TO GREGORIAN CALENDAR DATE (MONTH/DAY/YEAR)
Dim X As Long
Dim Z As Long
Dim F As Long
Dim A As Long
Dim B As Long
Dim C As Long
Dim D As Long
Dim G As Long
Dim UT As Long
Dim m As Long
Dim Y As Long
Dim IDS As Long
Dim Year As Long
Dim Month As Long
Dim Day As Long
Dim rs As DAO.Recordset
Dim RCt As Long
Dim strSql As String
Dim i As Integer
Dim SmpDate As String
Dim db As Database
Dim LUpdate As String
strSql = "Select ID from SampDateLink"
Set db = CurrentDb()
Set rs = DBEngine(0)(0).OpenRecordset(strSql)
RCt = DCount("*", "SampDateLink") 'Count # of records
i = 0
Do While i <= RCt
IDS = rs.AbsolutePosition + 1
On Error Resume Next
X = DLookup("[LocDate]", "SampDateLink", "[ID] =" & IDS)
Z = Int(X)
F = X - Z
Y = Int((Z - 1867216.25) / 36524.25)
A = Z + 1 + Y - Int(Y / 4)
B = A + 1524
C = Int((B - 122.1) / 365.25)
D = Int(365.25 * C)
G = Int((B - D) / 30.6001)
If G < 13.5 Then
Month = G - 1
Else
Month = G - 13
End If
If Month < 2.5 Then
Year = C - 4715
Else
Year = C - 4716
End If
UT = B - D - Int(30.6001 * G) + F
Day = Int(UT)
SmpDate = Month & "/" & Day & "/" & Year
LUpdate = "Update [SampDateLink] set [SampDate] = #" & _
Format(SmpDate, "mm/dd/yyyy") & "# Where [ID] = " & IDS
db.Execute LUpdate
i = i + 1
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Set db = Nothing
End Function
Thanks in advance,
Al
table, converts them to Gregorian Dates, and then updates an empty field in
the same table.
The table is a temporary table that is generated through a prior query then
updated using this Julian date function. I am trying to set up a custom
reporting feature from a Pervasive SQL Server ODBC connection where the dates
are stored as Julian dates and then use the converted dates to link back to
dates in another database to gather the data needed for the report.
Below is my working code that converts 13,000 records in about 2 minutes,
which I feel is much too slow. There has to be a better way to do this.
Public Function SampDCal()
'CONVERTS JULIAN DATE TO GREGORIAN CALENDAR DATE (MONTH/DAY/YEAR)
Dim X As Long
Dim Z As Long
Dim F As Long
Dim A As Long
Dim B As Long
Dim C As Long
Dim D As Long
Dim G As Long
Dim UT As Long
Dim m As Long
Dim Y As Long
Dim IDS As Long
Dim Year As Long
Dim Month As Long
Dim Day As Long
Dim rs As DAO.Recordset
Dim RCt As Long
Dim strSql As String
Dim i As Integer
Dim SmpDate As String
Dim db As Database
Dim LUpdate As String
strSql = "Select ID from SampDateLink"
Set db = CurrentDb()
Set rs = DBEngine(0)(0).OpenRecordset(strSql)
RCt = DCount("*", "SampDateLink") 'Count # of records
i = 0
Do While i <= RCt
IDS = rs.AbsolutePosition + 1
On Error Resume Next
X = DLookup("[LocDate]", "SampDateLink", "[ID] =" & IDS)
Z = Int(X)
F = X - Z
Y = Int((Z - 1867216.25) / 36524.25)
A = Z + 1 + Y - Int(Y / 4)
B = A + 1524
C = Int((B - 122.1) / 365.25)
D = Int(365.25 * C)
G = Int((B - D) / 30.6001)
If G < 13.5 Then
Month = G - 1
Else
Month = G - 13
End If
If Month < 2.5 Then
Year = C - 4715
Else
Year = C - 4716
End If
UT = B - D - Int(30.6001 * G) + F
Day = Int(UT)
SmpDate = Month & "/" & Day & "/" & Year
LUpdate = "Update [SampDateLink] set [SampDate] = #" & _
Format(SmpDate, "mm/dd/yyyy") & "# Where [ID] = " & IDS
db.Execute LUpdate
i = i + 1
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Set db = Nothing
End Function
Thanks in advance,
Al