title: Determining "days" in python when the timedelta.days is less than one
body: <p>sorry in advance if this is dense. I am trying to find the days since I last posted a tweet. The problem I am running into is when the dates are different, e.g., today and yesterday, but not enough hours have passed to be a full "day."</p>
  
  <pre><code># "created_at" is part of the Twitter API, returned as UTC time. The 
  # timedelta here is to account for the fact I am on the west coast, USA 
  lastTweetAt =  result.created_at + timedelta(hours=-8)
  
  # get local time
  rightNow = datetime.now()
  
  # subtract the two datetimes (which gives me a timedelta)
  dt = rightNow - lastTweetAt
  
  # print the number of days difference
  print dt.days
  </code></pre>
  
  <p>The problem is that if I posted a tweet at say 5 PM yesterday and am running the script at 8 AM today, only 15 hours have passed, which is 0 days. But obviously I want to say it's been 1 day since my last tweet if it was yesterday. And a kludge of adding "+1" isn't going to help because if I have tweeted today, I want the result to be 0.</p>
  
  <p>Is there a better approach than using timedelta to get the difference?</p>
  
  <hr/>
  
  <p><strong>Solution</strong> 
  <em>provided by Matti Lyra</em>  </p>
  
  <p>The answer is to call .date() on the datetimes so they are converted to coarser date objects (without timestamps).  The correct code looks like:</p>
  
  <pre><code># "created_at" is part of the Twitter API, returned as UTC time.
  # the -8 timedelta is to account for me being on the west coast, USA
  lastTweetAt =  result.created_at + timedelta(hours=-8)
  
  # get UTC time for right now
  rightNow = datetime.now()
  
  # truncate the datetimes to date objects (which have dates, but no timestamp)
  # and subtract them (which gives me a timedelta)
  dt = rightNow.date() - lastTweetAt.date()
  
  # print the number of days difference
  print dt.days
  </code></pre>