Convert Julian to Date

R

Reggie

Hi and TIA! I've researched and tried many many conversion functions but
none give me the results. One Example


Public Function JDatetoDate(MyDate As Integer) As Date

JDatetoDate = DateAdd("d", Right(MyDate, 3) - 1, "01/01/" &
Left(year(Now()), 3) & Left(MyDate, 1))

End Function

?JDatetoDate(8044) returned 2/13/2018 expected 2/13/2008
?JDatetoDate(0044) returned 2/13/2014 expected 2/13/2010

Any ideas. Basically want to convert a 4 digit julian to a date/time and
then I will add 1 minute to it. Thanks!
 
J

John W. Vinson

Hi and TIA! I've researched and tried many many conversion functions but
none give me the results. One Example


Public Function JDatetoDate(MyDate As Integer) As Date

JDatetoDate = DateAdd("d", Right(MyDate, 3) - 1, "01/01/" &
Left(year(Now()), 3) & Left(MyDate, 1))

End Function

?JDatetoDate(8044) returned 2/13/2018 expected 2/13/2008
?JDatetoDate(0044) returned 2/13/2014 expected 2/13/2010

Any ideas. Basically want to convert a 4 digit julian to a date/time and
then I will add 1 minute to it. Thanks!

You don't have a Y2K millenium problem - you have a decade problem! How do you
decide that 8 is 2008 as opposed to 2018, since the latter is in the current
decade? What would 2044 be: 2002 or 2012? How can you decide?

That said, you're applying the Left function to a Number, which won't
necessarily give you what you want. I'd use the DateSerial function instead:

DateSerial(10 * (Year(Date())\10) + Val(Left([MyDate], 1), 1,
Val(Right([MyDate], 3)))

This will return a date in the current decade. Since that isn't apparently
what you want, you may want to subtract 10 years from the first expression
under certain circumstances that you would understand better than I do!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top