title: How to calculate datetime difference using Django and python
body: <p>I need some help. I need to calculate datetime difference by matching with DB <code>date</code> field value. Here I am getting some error. I am explaining the error below.</p>
  
  <blockquote>
    <p>Error:</p>
  </blockquote>
  
  <pre><code>expected string or buffer
  Request Method: POST
  Request URL:    http://127.0.0.1:8000/loginsave/
  Django Version: 1.11.2
  Exception Type: TypeError
  Exception Value:    
  expected string or buffer
  Exception Location: /usr/local/lib/python2.7/dist-packages/django/utils/dateparse.py in parse_datetime, line 94
  Python Executable:  /usr/bin/python
  Python Version: 2.7.6
  </code></pre>
  
  <p>I am explaining my code below.</p>
  
  <pre><code>pers = User.objects.get(pk=uid)
  if int(cnt) == 3:
      pers.status = 1;
      pers.date = datetime.now
      pers.save()
  else:
      cnt1 = int(cnt)+1
      pers.count = cnt1
      pers.save()
  </code></pre>
  
  <p>Here I am getting error inside the <code>if statement</code>. Here I am storing the datetime inside the db. Here I need to calculate the difference with todays datetime value and the difference should be in hours(<code>i.e-1hrs,2hrs...</code>). Please help.</p>