Results 1 to 3 of 3

Thread: Convert Ordinal Date to Georgian Date Format

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2004
    Posts
    30

    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:
    1. 'Call function to convert "2007296" into "10/23/2007"
    2. ConvertOrdinalDate(2007296)
    3.  
    4. Function ConvertOrdinalDate(dt As Long) As Date
    5.     Dim YYYY As Integer
    6.     Dim DDD As Integer
    7.     YYYY = Left(dt, 4)
    8.     DDD = Right(dt, 3)
    9.     If IsMissing(YYYY) Then YYYY = year(Date)
    10.     If Not IsNumeric(YYYY) Or YYYY \ 1 <> YYYY Or YYYY < 100 Or YYYY > 9999 Then
    11.         Exit Function
    12.     End If
    13.     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
    14.         ConvertOrdinalDate = DateSerial(YYYY, 1, DDD)
    15.     End If
    16. End Function

    Hoped this code snippet helps someone.
    -Chris
    Last edited by Hack; Oct 24th, 2007 at 05:50 AM.

  2. #2
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    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

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Convert Ordinal Date to Georgian Date Format

    Moved to the CodeBank

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width