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']

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

  • $\begingroup$ 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. $\endgroup$ – planetmaker Jun 13 '20 at 22:58
  • $\begingroup$ what is the dictionay hminew? Can you create a minimal example that I could copy and paste to generate this error? $\endgroup$ – James K Jun 14 '20 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’


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.

You can add this to your Python script.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.