Calculating julian date in python

edub picture edub · Jun 30, 2015 · Viewed 22.4k times · Source

I'm trying to create a julian date in python and having major struggles. Is there nothing out there as simple as:

jul = juliandate(year,month,day,hour,minute,second)

where jul would be something like 2457152.0 (the decimal changing with the time)?

I've tried jdcal, but can't figure out how to add the time component (jdcal.gcal2jd() only accepts year, month and day).

Answer

Janos Hajagos picture Janos Hajagos · Apr 21, 2017

Not a pure Python solution but you can use the SQLite in memory db which has a julianday() function:

import sqlite3
con = sqlite3.connect(":memory:")
list(con.execute("select julianday('2017-01-01')"))[0][0]

which returns: 2457754.5