Countdown to an event

EasyDatetime Programs · 19 of 20

Write a Python program that prints the days, hours and minutes until an event.

Advertisement
Output
59 days, 13 hours, 59 minutes

Approach

  1. Split a timedelta with divmod.

Solution

Python
from datetime import datetime now = datetime(2026, 11, 2, 10, 0)event = datetime(2026, 12, 31, 23, 59)left = event - nowhours, rest = divmod(left.seconds, 3600)print(f"{left.days} days, {hours} hours, {rest // 60} minutes")
Output
59 days, 13 hours, 59 minutes

Learn the concept

New to this topic? Read the lesson, then come back.

More datetime programs

← All 20 Datetime Programs

Leave a Comment