<p>The accepted string formats for date-hms are:</p>

<pre><code>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’
</code></pre>

<p><a href="https://docs.astropy.org/en/stable/time/index.html" rel="nofollow noreferrer">https://docs.astropy.org/en/stable/time/index.html</a></p>

<p>You can either change one of these, or you can define your own format by deriving a class for the format from the <code>TimeFormat</code> class.
<a href="https://docs.astropy.org/en/stable/api/astropy.time.TimeFormat.html#astropy.time.TimeFormat" rel="nofollow noreferrer">https://docs.astropy.org/en/stable/api/astropy.time.TimeFormat.html#astropy.time.TimeFormat</a></p>

CC BY-SA 4.0
2020-06-14T14:37:43.737Z
2020-06-14T14:37:43.737Z
James K
<p>It looks as if your input had the wrong format. Read the algorithm to see what formats is expected.</p>

<p>There is an algorithm for converting between our current date and time to Julian date.  The reference for this is <a href="http://articles.adsabs.harvard.edu/cgi-bin/nph-iarticle_query?bibcode=1983IAPPP..13...16F&amp;db_key=AST&amp;page_ind=0&amp;data_type=GIF&amp;type=SCREEN_VIEW&amp;classic=YES" rel="nofollow noreferrer">here.</a> I also have a very short fortran code that calculate JD as well.</p>

<p>You can add this to your Python script.</p>

CC BY-SA 4.0
2020-06-13T23:05:05.167Z
2020-06-13T23:29:39.293Z
2020-06-13T23:29:39.293Z
Natsfan
<p>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:</p>

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

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

<pre><code>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']
</code></pre>

<p>Does anyone know what is wrong? How can I convert my dates??
Thanks</p>

CC BY-SA 4.0
2020-06-13T22:58:51.577Z
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
CC BY-SA 4.0
2020-06-14T07:42:28.197Z
what is the dictionay hminew?  Can you create a minimal example that I could copy and paste to generate this error?
James K
<time><python><astropy>
Convert dates to julian day number in astropy?
Vanessa
# Convert dates to julian day number in astropy?

(Asked by: username_0 on 2020-06-13)

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

**Tags:** time, python, astropy
> **Comments:**
> **username_1**: 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.  
> **username_2**: what is the dictionay hminew?  Can you create a minimal example that I could copy and paste to generate this error?  

---

## 2 answers

### Answer by username_2 on 2020-06-14. Score: 3

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


---

### Answer by username_3 on 2020-06-13. Score: 1

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.](http://articles.adsabs.harvard.edu/cgi-bin/nph-iarticle_query?bibcode=1983IAPPP..13...16F&db_key=AST&page_ind=0&data_type=GIF&type=SCREEN_VIEW&classic=YES) I also have a very short fortran code that calculate JD as well.

You can add this to your Python script.


---

