Convert DAY IN YEAR to date

  • Thread starter Thread starter fdnyfish via AccessMonster.com
  • Start date Start date
F

fdnyfish via AccessMonster.com

I have a number "312" and I know it's year 2007. How do I figure convert 312
to the 312th day of 2007?
 
With the year and the day number, what you have is a Julian date. Here is a
function that will convert a Julian date to a serial date:

Public Function JulianToSerial(lngJulianDate As Long) As Date
Dim serialdate As Date
JulianToSerial = DateSerial(((Year(Date) \ 10) * 10) + Int(lngJulianDate
/ 1000), 1, lngJulianDate Mod 1000)
End Function
 
no way to do this in a query?
With the year and the day number, what you have is a Julian date. Here is a
function that will convert a Julian date to a serial date:

Public Function JulianToSerial(lngJulianDate As Long) As Date
Dim serialdate As Date
JulianToSerial = DateSerial(((Year(Date) \ 10) * 10) + Int(lngJulianDate
/ 1000), 1, lngJulianDate Mod 1000)
End Function
 
You can call a function in a query. The function has to be a Public function
in a standard module. Then you use a calculated field to return the results:

RealDate: JulianToSerial(Clng(Format(Year(SomeDAte),"##") + DayNumber))
 
I have a number "312" and I know it's year 2007. How do I figure convert 312
to the 312th day of 2007?

Klatuu's code may be overkill for this case: you can put a calculated field in
a Query

TheDate: DateSerial(Year(Date()), 1, [yournumberfield])


John W. Vinson [MVP]
 
Now why didn't I think of that?
--
Dave Hargis, Microsoft Access MVP


John W. Vinson said:
I have a number "312" and I know it's year 2007. How do I figure convert 312
to the 312th day of 2007?

Klatuu's code may be overkill for this case: you can put a calculated field in
a Query

TheDate: DateSerial(Year(Date()), 1, [yournumberfield])


John W. Vinson [MVP]
 
Back
Top