ChrisR873
Oct 23rd, 2007, 04:59 PM
Note: I'm posting this as finished working code. I was looking for how to do this throughout the forum and web but had difficulties finding what I needed and all the code that was posted here was complicated or more difficult then needed. Moderator please move to correct section if improperly placed. Thanks!
Ordinal Date is frequently incorrectly referred to as Julian Date. Ref: Link (http://en.wikipedia.org/wiki/ISO_8601)
'Call function to convert "2007296" into "10/23/2007"
ConvertOrdinalDate(2007296)
Function ConvertOrdinalDate(dt As Long) As Date
Dim YYYY As Integer
Dim DDD As Integer
YYYY = Left(dt, 4)
DDD = Right(dt, 3)
If IsMissing(YYYY) Then YYYY = year(Date)
If Not IsNumeric(YYYY) Or YYYY \ 1 <> YYYY Or YYYY < 100 Or YYYY > 9999 Then
Exit Function
End If
If DDD > 0 And DDD < 366 Or DDD = 366 And YYYY Mod 4 = 0 And YYYY Mod 100 <> 0 Or YYYY Mod 400 = 0 Then
ConvertOrdinalDate = DateSerial(YYYY, 1, DDD)
End If
End Function
Hoped this code snippet helps someone.
-Chris
Ordinal Date is frequently incorrectly referred to as Julian Date. Ref: Link (http://en.wikipedia.org/wiki/ISO_8601)
'Call function to convert "2007296" into "10/23/2007"
ConvertOrdinalDate(2007296)
Function ConvertOrdinalDate(dt As Long) As Date
Dim YYYY As Integer
Dim DDD As Integer
YYYY = Left(dt, 4)
DDD = Right(dt, 3)
If IsMissing(YYYY) Then YYYY = year(Date)
If Not IsNumeric(YYYY) Or YYYY \ 1 <> YYYY Or YYYY < 100 Or YYYY > 9999 Then
Exit Function
End If
If DDD > 0 And DDD < 366 Or DDD = 366 And YYYY Mod 4 = 0 And YYYY Mod 100 <> 0 Or YYYY Mod 400 = 0 Then
ConvertOrdinalDate = DateSerial(YYYY, 1, DDD)
End If
End Function
Hoped this code snippet helps someone.
-Chris