# Convert dates to julian day number in astropy?

I'm using astropy and I need to convert dates like this: 2012.06.22_17:56:15_TAI into julian day number. I tried:

from astropy.time import Time
hmitime = hminew['MidTime']
i=0
print(hmitime[i])
hmi0=Time(hmitime[i],scale='tai')
print(hmi0.jd)


where hmitime it's just the matrix with my dates. But python shows me this:

ValueError: Input values did not match any of the formats where the format keyword is optional [u'datetime', u'iso', u'isot', u'yday', u'fits', u'byear_str', u'jyear_str']


Does anyone know what is wrong? How can I convert my dates?? Thanks

• I think an actual verbatim example of your input data including spaces etc might be crucial to identify your problem... it's a ValueError after all. – planetmaker Jun 13 at 22:58
• what is the dictionay hminew? Can you create a minimal example that I could copy and paste to generate this error? – James K Jun 14 at 7:42

The accepted string formats for date-hms are:

Format  Class    Example argument

fits    TimeFITS    ‘2000-01-01T00:00:00.000’
iso     TimeISO     ‘2000-01-01 00:00:00.000’
isot    TimeISOT    ‘2000-01-01T00:00:00.000’


https://docs.astropy.org/en/stable/time/index.html

You can either change one of these, or you can define your own format by deriving a class for the format from the TimeFormat class. https://docs.astropy.org/en/stable/api/astropy.time.TimeFormat.html#astropy.time.TimeFormat

It looks as if your input had the wrong format. Read the algorithm to see what formats is expected.

There is an algorithm for converting between our current date and time to Julian date. The reference for this is here. I also have a very short fortran code that calculate JD as well.