Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Use <a href="http://docs.python.org/library/time.html#time.strptime" rel="nofollow noreferrer">strptime</a>.</p> <p>Sample usage:</p> <pre><code>from datetime import datetime my_date = datetime.strptime('Mon Jun 28 10:51:07 2010', '%a %b %d %H:%M:%S %Y') print my_date </code></pre> <p><strong>EDIT:</strong></p> <p>You could also print the time difference in a human readable form, like so:</p> <pre><code>from time import strptime from datetime import datetime def date_diff(older, newer): """ Returns a humanized string representing time difference The output rounds up to days, hours, minutes, or seconds. 4 days 5 hours returns '4 days' 0 days 4 hours 3 minutes returns '4 hours', etc... """ timeDiff = newer - older days = timeDiff.days hours = timeDiff.seconds/3600 minutes = timeDiff.seconds%3600/60 seconds = timeDiff.seconds%3600%60 str = "" tStr = "" if days &gt; 0: if days == 1: tStr = "day" else: tStr = "days" str = str + "%s %s" %(days, tStr) return str elif hours &gt; 0: if hours == 1: tStr = "hour" else: tStr = "hours" str = str + "%s %s" %(hours, tStr) return str elif minutes &gt; 0: if minutes == 1:tStr = "min" else: tStr = "mins" str = str + "%s %s" %(minutes, tStr) return str elif seconds &gt; 0: if seconds == 1:tStr = "sec" else: tStr = "secs" str = str + "%s %s" %(seconds, tStr) return str else: return None older = datetime.strptime('Mon Jun 28 10:51:07 2010', '%a %b %d %H:%M:%S %Y') newer = datetime.strptime('Tue Jun 28 10:52:07 2010', '%a %b %d %H:%M:%S %Y') print date_diff(older, newer) </code></pre> <p><a href="http://djangosnippets.org/snippets/412/" rel="nofollow noreferrer">Original source</a> for the time snippet.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload