Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

subtract 2 datetime objects django

# You can just subtract the dates directly, which will yield a datetime.timedelta object:

dt = weight_now.weight_date - weight_then.weight_date

# A timedelta object has fields for days, seconds, and microseconds.
# From there, you can just do the appropriate math. For example:

hours = dt.seconds / 60 / 60    # Returns number of hours between dates
weeks = dt.days / 7   
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #subtract #datetime #objects #django
ADD COMMENT
Topic
Name
4+6 =