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

Oct 31, 2019
import datetimenow = datetime.datetime.now()target = datetime.datetime(2019, 10, 1)delta = now - target# days diff# if now > target, value will be positivedays = delta.daystotal_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]

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.