Python Diff Between Two Dates (Days, Hours, Minutes, Seconds)

October 31, 2019
import datetime

now = datetime.datetime.now()
target = datetime.datetime(2019, 10, 1)


delta = now - target

# days diff
# if now > target, value will be positive
days = delta.days


total_seconds = (now - target).total_seconds()

days = divmod(total_seconds, 60*60*24)[0]

hours = divmod(total_seconds,  60*60)[0]

minutes = divmod(total_seconds,  60)[0]
This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.