title: Changing Time Type for Postgres In Python
body: <p>I have times from a table that take this form:</p>
  
  <pre><code>2017-12-31T23:59:59.8560818Z
  </code></pre>
  
  <p>I'm not entirely sure what form this actually is. All I know is that I want to convert it in python to a type of time that is acceptable to insert into a postgres table as a timestamp or date (I really only care about the date). Any ideas for a better way to do this than just taking a substring of the date?</p>
  
  <p>When I try this:</p>
  
  <pre><code>exchange_rate['time'] = str(exchange_rate['time'])[:10]  #captures the YYY-MM-DD from date
  exchange_rate['time'] = datetime.datetime.strptime(exchange_rate['time'], '%Y-%m-%d') #converts to datetime
  
  cursor.execute('''INSERT INTO bitcoin VALUES ({},{})'''.format(exchange_rate['time'],exchange_rate['rate']))
  </code></pre>
  
  <p>I get this error:</p>
  
  <p><a href="https://i.stack.imgur.com/P5tqb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/P5tqb.png" alt="enter image description here"></a></p>