Date & Time: Practice Questions
100 questions. Try each one yourself before checking the answer.
Short on time? Filter by Must Do for the 25 questions that cover this topic on their own.
Get today's date and the current moment, and look at what each one gives you.
Build a date yourself, and see what happens when the values are impossible.
Read the parts of a date back out.
Build a datetime with as much or as little precision as you need.
Read every part of a datetime, including the ones a date does not have.
Use a time object for a clock reading with no date attached.
Join a date and a time into a datetime, and split one back apart.
See what str() and repr() give you for each type.
Write and read the one date format you should always prefer.
Compare and sort dates.
Create durations with timedelta.
Add and subtract durations to move around the calendar.
Find the gap between two dates.
Take a timedelta apart correctly.
Find out which day of the week a date falls on.
Format a date for a human to read.
Print day and month names instead of numbers.
Turn a date string back into a datetime.
Find the boundaries of what these types can hold.
Change one field of a date by making a modified copy.
Convert between a datetime and a Unix timestamp.
Use the older time module alongside datetime.
Answer calendar questions the datetime module does not.
Get the current time in UTC — the modern way and the deprecated way.
Sort records by their date.
Build a runnable reference for every directive you will actually use.
Understand exactly why a parse fails, and validate a date properly.
Accept a date in any of several formats.
Remove the leading zeros from a formatted date without breaking on another platform.
Read and write the full ISO format, including offsets.
Work with week numbers, and see why there are three different ones.
Do maths with durations themselves.
Print a duration the way a human would say it.
Convert a date to a single number and back.
Add months to a date, given that timedelta cannot.
Find the first and last day of a month, quarter and year.
Print a real calendar.
Count and skip working days.
Calculate someone's age correctly.
Attach a fixed UTC offset to a datetime and see what changes.
Use real named time zones, which know about daylight saving.
Convert a moment between time zones without changing the moment.
Look at the hour that does not exist and the hour that happens twice.
Choose the right clock for measuring how long something took.
Build a stopwatch as a context manager and as a decorator.
Truncate and round a datetime to a chosen unit.
Generate a series of dates lazily.
Group dated records into months, weeks and quarters.
Pull dates out of free text with a regex, then parse them properly.
Turn a datetime into "3 hours ago" or "in 2 days".
Find a meeting slot that works for a team spread across time zones.
Track deadlines and report what is overdue, due soon and on track.
Turn raw punch-in and punch-out stamps into an attendance register.
Filter a log to a time window, and summarise what happened in it.
Generate a recurring schedule: daily, weekly, monthly.
Build a countdown to an event with a progress bar.
Measure elapsed time counting only office hours.
Work out subscription renewal dates and a prorated charge.
Build a birthday reminder list that handles the year rollover.
Write dates to CSV and JSON, and read them back exactly.
Build an hourly histogram of events.
Summarise a set of durations properly.
Print a month calendar with events marked on it.
Total a week of HH:MM entries and work out overtime.
Work out a delivery date from an order time and a daily cutoff.
Sort and display a feed of events submitted from different time zones.
Implement a rate limiter with a sliding window.
Split a stream of activity into sessions using an inactivity timeout.
Map calendar dates onto a financial year that does not start in January.
Find free slots in a day given a list of existing bookings.
This function crashes on some inputs and not others. Explain why and fix it.
from datetime import datetime, timezone
def hours_until(deadline):
return (deadline - datetime.now()).total_seconds() / 3600
print(hours_until(datetime(2030, 1, 1)))
print(hours_until(datetime(2030, 1, 1, tzinfo=timezone.utc)))Show the silent bug that datetime.utcnow() causes.
Show that "add one day" and "add 24 hours" are different answers.
Show the bug caused by reading .seconds instead of .total_seconds().
Handle 29 February and the century rule.
See where %y decides a two-digit year belongs.
Show why sorting dates as strings works in exactly one format.
Watch precision disappear when datetimes become floats.
Show where .replace() raises, and what to use instead.
Show how a timestamp goes wrong when the timezone is left out.
Show the week-numbering bug that appears once a year.
Show why time.time() is the wrong clock for a timeout.
This holiday calculator reports the wrong number of days. Find the off-by-one.
from datetime import date
def holiday_days(first_day, last_day):
return (last_day - first_day).days
print(holiday_days(date(2024, 8, 12), date(2024, 8, 16)))
print(holiday_days(date(2024, 8, 12), date(2024, 8, 12)))Show what happens when date.today() is used as a default argument.
Show which parts of date formatting are not portable.
Build an Attendance & Payroll Report from raw shift records.
Build a Project Schedule Planner with dependencies and a text Gantt chart.
Build a World Clock Dashboard showing one instant everywhere.
Build a Log Analytics Report with time bucketing and incident detection.
Build a Recurring Event Engine driven by rules.
Build a Flight Itinerary calculator across time zones.
Build a Habit Tracker with streaks and a heat map.
Build an Invoice Ageing Report with buckets and interest.
Build a Server Uptime Analyser from a stream of status changes.
Build a Personal Calendar with conflict detection and a free/busy view.
Explain naive versus aware datetimes completely, with every rule that follows from it.
Map the whole datetime API: what each call takes and what it gives back.
State the rules for storing and exchanging time, and demonstrate what each one prevents.
Catalogue the failure modes of date handling, with a demonstration of each.
Build a Global Event Platform — the complete demonstration of this topic. Ingest events in mixed formats and zones, validate them, expand recurring rules, detect conflicts, and produce a per-viewer schedule with a full report.
Still stuck on something?
Book a free 1-on-1 session and we'll work through it together.
Book a Free Session