Answers for "subtract 2 datetime objects django"

0

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
Posted by: Guest on March-16-2022

Code answers related to "subtract 2 datetime objects django"

Python Answers by Framework

Browse Popular Code Answers by Language