Get full date given a short julian date


Question


My company uses abbreviated julian dates to show absolute day of the year when a task was completed. For example, 2001 is Jan 1, 2002. (It could also be Jan 1 of 1992 or 82 etc). I want to assume the first digit is the current or most recent previous year, and then calculate the date.

Answer

Here is the code to calculate full date given short julian date:

Public Function GetDateByShortJulianDate( _
                ByVal vintShortJulianDate As Integer, _
                Optional ByVal vdatCurrDate As Long = 0) As Date
    ' Get full date given a short julian date
    ' Written by Shamil Salakhetdinov, Spb, RUSSIA
    Dim intCurrCD As Integer     ' current date's century and decade
    Dim intCurrYear As Integer   ' current date's yearnum
    Dim intDay As Integer        ' short julian date's daynum
    Dim intYear As Integer       ' short julian date's yearnum
    Dim intYYYY As Integer       ' short julian date's full year
    
    If vdatCurrDate = 0 Then vdatCurrDate = Date
    intCurrCD = CInt(Left(Format(Year(vdatCurrDate), "0000"), 3))
    intCurrYear = CInt(Right(Format(Year(vdatCurrDate), "0000"), 1))
    intYear = CInt(Left(Format(vintShortJulianDate, "0000"), 1))
    intDay = CInt(Mid(Format(vintShortJulianDate, "0000"), 2))
    If intYear > intCurrYear Then intCurrCD = intCurrCD - 1
    intYYYY = intCurrCD * 10 + intYear
    GetDateByShortJulianDate = DateSerial(intYYYY, 1, intDay)
ErrHandler:
End Function

Copyright 1999-2008 by Shamil Salakhetdinov. All rights reserved.