Day of year to date

goyo

New member
Local time
Today, 11:23
Joined
Nov 30, 2015
Messages
2
I am brand new to MS Access and just starting out.:banghead: I was wondering if I could get some help on converting a 4 digit number in to a date. For example: 1485=>May 28 2015. But I am not surer how to do this in Access?
 
Check out the DateAdd() function. You can add the number of days to January 1 of the appropriate year.
 
Now the dates that are going to be entered are going to be from 2013, 2014, 2015 and 2016. So how would l enter the data then?

IE: 3614=12/27/14
 
Left() and Right() functions can get you the two parts needed.
 
Code:
'**********************************************
'* fnJulian2Date
'*
'* developed by arnelgp
'* for goyo
'* 01-dec-2015
'*
'* parameter:
'*      JulDay As Integer in the format (dddy)
'*
'* return value:
'*      Date
'***********************************************
Function fnJulian2Date(JulDay As Integer)
        
    Dim intYear As Integer, intDays As Integer, i As Integer
    Dim strJulDay As String
    
    strJulDay = CStr(JulDay)
    intYear = Val(Right(strJulDay, 1))
    intYear = 2010 + intYear
    JulDay = Val(Left(strJulDay, Len(strJulDay) - 1))
    
    For i = 2 To 13
        intDays = Val(Format(DateSerial(intYear, i, 0), "dd"))
        If intDays <= JulDay Then Exit For
        JulDay = JulDay - intDays
    Next
    fnJulian2Date = DateSerial(intYear, i - 1, JulDay)
        
End Function
 
Last edited:
try

dateadd("d",val(left(datenum,3)),dateadd("yyyy",val(right(datenum,1),#01/01/2010#)
 
Or try . . .
Code:
Function GetDateFromJulian(julian As Integer) As Date
    Dim year As Integer
    Dim days As Integer
    
    year = Right(day, 1) + 2010
    days = Left(julian, Len(julian) - 1)
    
    GetDateFromJulian = DateSerial(year, 1, days)
End Function
 

Users who are viewing this thread

Back
Top Bottom