title: Python: AttributeError: 'str' object has no attribute 'datetime'
body: <p>I am using this code: </p>
  
  <pre><code>def calcDateDifferenceInMinutes(end_date,start_date):
      fmt = '%Y-%m-%d %H:%M:%S'
      start_date_dt = datetime.strptime(start_date, fmt)
      end_date_dt = datetime.strptime(end_date, fmt)
  
  # convert to unix timestamp
  start_date_ts = time.mktime(start_date_dt.timetuple())
  end_date_ts   = time.mktime(end_date_dt.timetuple())
  
  # they are now in seconds, subtract and then divide by 60 to get minutes.
  return (int(end_date_ts-start_date_ts) / 60)
  </code></pre>
  
  <p>from this question: <a href="https://stackoverflow.com/questions/2788871/python-date-difference-in-minutes/6879077#6879077">stackoverflow question</a></p>
  
  <p>But I'm getting this message:</p>
  
  <blockquote>
    <p>AttributeError: 'str' object has no attribute 'datetime'</p>
  </blockquote>
  
  <p>I've reviewed similar questions but don't see any alternatives other than to do something like:</p>
  
  <pre><code>start_date_dt = datetime.datetime.strptime(start_date, fmt)
  </code></pre>
  
  <p>Here's the full trace:</p>
  
  <pre><code>&gt; Traceback (most recent call last):   File "tabbed_all_cols.py", line
  &gt; 156, in &lt;module&gt;
  &gt;     trip_calculated_duration = calcDateDifferenceInMinutes (end_datetime,start_datetime)   File "tabbed_all_cols.py", line 41, in
  &gt; calcDateDifferenceInMinutes
  &gt;     start_date_dt = datetime.datetime.strptime(start_date, fmt) AttributeError: 'str' object has no attribute 'datetime'
  </code></pre>
  
  <p>And line 41 is: </p>
  
  <blockquote>
  <pre><code>start_date_dt = datetime.datetime.strptime(start_date, fmt)
  </code></pre>
  </blockquote>
  
  <p>Can someone shed light on what I'm missing?</p>
  
  <p><strong>New Update</strong>: I'm still trying to figure this out. I see that version is important. I am using version 2.7 and am importing datetime.</p>
  
  <p>I don't think I am setting the string date back to a string, which is what I think people are suggesting below.</p>
  
  <p>Thanks</p>