2

I find myself struggling with this problem: I need to convert a julian date to normal date ("YYYY-MM-DD") in R. I'm aware that I can specify as.Date(julian_date,origin=""), but I don't know which origin should be provided.

My julian dates are something like 2458010,2458011 etc.. If I stay with default origin ("1970-01-01") my dates becomes something like "8699-11-10" which is obviously wrong since I know dates should be in years 2017-2018

How do I know the correct origin for the as.Date function? http://www.onlineconversion.com/julian_date.htm This site seems to convert my julian dates in the right way...

M--
  • 25,431
  • 8
  • 61
  • 93
Marco Fumagalli
  • 2,307
  • 3
  • 23
  • 41
  • Does this answer your question: https://stackoverflow.com/questions/20789612/convert-julian-date-to-calendar-dates-within-a-data-frame-in-r – DTYK Sep 13 '18 at 08:14
  • Nope.. As I said it returns me 8699 as year which is not correct. – Marco Fumagalli Sep 13 '18 at 08:16
  • Ok, I answer myself... maybe the origin date is -4713-01-01 G, the first cycle of julian date. https://whatis.techtarget.com/definition/Julian-date.. Now the problem is how to pass that number to the as.Date function – Marco Fumagalli Sep 13 '18 at 08:19

1 Answers1

5

Julian day number 0 is assigned to the day starting at noon on November 24, 4714 BC (wikipedia).

Wikipedia example:

as.Date(2451545, origin = structure(-2440588, class = "Date"))
[1] "2000-01-01"

Your example:

as.Date(c(2458010,2458011), origin = structure(-2440588, class = "Date"))
[1] "2017-09-13" "2017-09-14"