I have a Julian date: 736257, I need help converting it from Julian date to Gregorian date in Python.
Asked
Active
Viewed 5,276 times
1
-
1Possible duplicate of [Python3 convert Julian date to standard date](https://stackoverflow.com/questions/37743940/python3-convert-julian-date-to-standard-date) – ndmeiri Apr 04 '18 at 22:58
-
@ndmeiri This appears to be the "days since 1AD" meaning of Julian date rather than the "year * 1000 + days since the start of this year" meaning, so that question and its answers won't help. – abarnert Apr 04 '18 at 22:59
-
Just to be clear, the number you've chosen translates to Friday, Oct 6, 2698 B.C. Does that match your expectation? – Robᵩ Apr 04 '18 at 23:02
-
@Robᵩ I suspect he means 21 Oct 2016. Astronomers aren't the only ones who use JDNs. – abarnert Apr 04 '18 at 23:04
1 Answers
3
The term "Julian date" has two different meanings, and different variations for each.
I think you're looking for the "days since epoch" meaning, and using the 1 Jan 1 CE epoch rather than the more common astronomers' epoch of 4713 BCE or any of the other alternatives. You can adjust that pretty easily.
>>> datetime.date(1, 1, 1) + datetime.timedelta(days=736257)
datetime.date(2016, 10, 21)
That's all there is to it. (Which is the point of using Julian dates in the first place.)
Notice that under the covers, this is the same format Python datetime
is already using, for its date
and datetime
types, except that Python uses midnight UTC instead of local noon. If that's what you want, it's even easier:
>>> datetime.date.fromordinal(736257)
datetime.date(2016, 10, 20, 0, 0)

abarnert
- 354,177
- 51
- 601
- 671
-
Thanks abarnert, how to i convert the gregorian date back to Julian date? – saum Apr 05 '18 at 03:47
-
All the options are in the docs I linked. You can use `toordinal` to get the Python definition, you can subtract `date(1,1,1)` to get a `timedelta` and pull the days out of that to get the other definition, etc. – abarnert Apr 05 '18 at 03:59
-
Thanks, i use the toordinal . >>>from datetime import datetime >>> datetime.strptime("2016-10-20", "%Y-%m-%d").toordinal() – saum Apr 05 '18 at 21:49