Convert Ordinal Date to Georgian Date Format
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
vb Code:
'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
Re: [RESOLVED] Convert Ordinal Date to Georgian Date Format
Code:
Public Function ConvertOrdinalDate(dt As Long) As Variant
On Error GoTo ErrHandler
ConvertOrdinalDate = DateSerial((dt \ 1000), 1, (dt Mod 1000))
Exit Function
ErrHandler:
MsgBox Err.Number & ": " & Err.Description, vbOKOnly, "Invalid Ordinal Date"
Err.Clear
End Function
Re: Convert Ordinal Date to Georgian Date Format