title: what is the proper way to convert between mysql datetime and python timestamp?
body: <p>according to <a href="http://dev.mysql.com/doc/refman/5.0/en/datetime.html" rel="noreferrer">http://dev.mysql.com/doc/refman/5.0/en/datetime.html</a>.  i got to find a way to convert the string value  'YYYY-MM-DD HH:MM:SS' to a timestamp int.</p>
  
  <p>i looked up in python's doc.</p>
  
  <p>i tried:</p>
  
  <pre><code>print(time.strptime('2013-01-12 15:27:43', '%Y-%m-%d %H:%M:%S'))   
  </code></pre>
  
  <p>python give me a result like this.</p>
  
  <p>time.struct_time(tm_year=2013, tm_mon=1, tm_mday=12, tm_hour=15, tm_min=27, tm_sec=43, tm_wday=5, tm_yday=12, tm_isdst=-1)</p>
  
  <p>i tried this to convert timestamp to YYYY-MM-DD HH:MM:SS format </p>
  
  <pre><code>print(time.strftime('%Y-%m-%d %H:%M:%S',time.time()))
  </code></pre>
  
  <p>python give me a type error.</p>
  
  <p>i only use timestamp to calculate time and date, i hope there's already a way in python, simple and efficient , and don't have to create temp data.</p>
  
  <p>according to the answer i write two methods. hope it would be helpful</p>
  
  <pre><code>import time
  
  def convertTimestampToSQLDateTime(value):
      return time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(value))
  
  def convertSQLDateTimeToTimestamp(value):
      return time.mktime(time.strptime(value, '%Y-%m-%d %H:%M:%S'))
  </code></pre>