Hi,
This is my first post, so please be patient if I messed it up.
The problem I have/had was converting a Julian date back into a normal calendar date and the following is what I came up with to do the job.
It's probably not very pretty from a programmers point of view, so any comments or suggestions will be very wellcome.
Patrck.
Sub CalDate()
Dim CalDate As Date 'Is the calander date preceding the Julian year eg 9365 is 31 Dec 2008
Dim JulianDate As Integer 'Julian date from the data base table, may be 4 or 5 characters long.
Dim JulianLength As Integer 'Length of Julian date, this will be 4 or 5 characters
Dim JulianDays As Integer '3 digits from R to L taken from the Julian date
Dim JulianYear As Integer '1 or 2 digits L to R from JulianDate to obtain the Year
Dim RecordDate As Date 'Reconstructed Calander date taken from the info in the Julian date.
Dim OffSet As Integer
Dim Increment As Integer
Dim strTest As String
Dim TestValues(3) As Integer
Dim TestCounter As Integer
TestValues(0) = "9345"
TestValues(1) = "10245"
TestValues(2) = "12110"
Increment = 0
For TestCounter = 0 To 2
strTest = StrConv(TestValues(TestCounter), vbLowerCase) ' need to get length of Julian date
JulianLength = Len(strTest)
If JulianLength = 4 Then OffSet = 1 Else OffSet = 2
JulianDate = TestValues(Increment)
JulianYear = Left$(JulianDate, OffSet)
JulianYear = JulianYear + 1999 ' all my Julian dates are after the year 2000
CalDate = DateSerial(JulianYear, 12, 31)
JulianDays = Right$(JulianDate, 3)
RecordDate = DateAdd("d", JulianDays, CalDate)
Debug.Print
Debug.Print RecordDate, " reconstructed calendar date"
Debug.Print
Debug.Print strTest, " original Julian date"
Debug.Print
Debug.Print JulianLength, " number of chacters in Julian date"
Increment = Increment + 1
Next TestCounter
End Sub
This is my first post, so please be patient if I messed it up.
The problem I have/had was converting a Julian date back into a normal calendar date and the following is what I came up with to do the job.
It's probably not very pretty from a programmers point of view, so any comments or suggestions will be very wellcome.
Patrck.
Sub CalDate()
Dim CalDate As Date 'Is the calander date preceding the Julian year eg 9365 is 31 Dec 2008
Dim JulianDate As Integer 'Julian date from the data base table, may be 4 or 5 characters long.
Dim JulianLength As Integer 'Length of Julian date, this will be 4 or 5 characters
Dim JulianDays As Integer '3 digits from R to L taken from the Julian date
Dim JulianYear As Integer '1 or 2 digits L to R from JulianDate to obtain the Year
Dim RecordDate As Date 'Reconstructed Calander date taken from the info in the Julian date.
Dim OffSet As Integer
Dim Increment As Integer
Dim strTest As String
Dim TestValues(3) As Integer
Dim TestCounter As Integer
TestValues(0) = "9345"
TestValues(1) = "10245"
TestValues(2) = "12110"
Increment = 0
For TestCounter = 0 To 2
strTest = StrConv(TestValues(TestCounter), vbLowerCase) ' need to get length of Julian date
JulianLength = Len(strTest)
If JulianLength = 4 Then OffSet = 1 Else OffSet = 2
JulianDate = TestValues(Increment)
JulianYear = Left$(JulianDate, OffSet)
JulianYear = JulianYear + 1999 ' all my Julian dates are after the year 2000
CalDate = DateSerial(JulianYear, 12, 31)
JulianDays = Right$(JulianDate, 3)
RecordDate = DateAdd("d", JulianDays, CalDate)
Debug.Print
Debug.Print RecordDate, " reconstructed calendar date"
Debug.Print
Debug.Print strTest, " original Julian date"
Debug.Print
Debug.Print JulianLength, " number of chacters in Julian date"
Increment = Increment + 1
Next TestCounter
End Sub