Python Practice › Datetime Programs
Python Datetime Programs with Solutions
20 datetime programs: creating dates, formatting and parsing, date arithmetic, ages, weekdays, month ends, business days and time zones. Programs use fixed dates so their output is repeatable.
Before you start
Read the Datetime lesson first if the topic is new to you.
All programs
- #1Create a date and read its parts
Write a Python program to create a date and print its year, month, day and weekday.Easy - #2Format a date
Write a Python program to print a date in several formats.Easy - #3Parse a date string
Write a Python program to convert the string “15/08/2026 09:30” into a datetime.Easy - #4Add and subtract days
Write a Python program to find the dates 30 days after and 7 days before a date.Easy - #5Days between two dates
Write a Python program to count the days between two dates.Easy - #6Calculate age
Write a Python program to calculate a person’s age on a given date.Easy - #7Day of the week for a date
Write a Python program to find the weekday of a date.Easy - #8Is a date a weekend?
Write a Python program to check whether dates fall on a weekend.Easy - #9Last day of a month
Write a Python program to find the last day of a month.Easy - #10Add months to a date
Write a Python program to add months to a date, clamping to the month’s last day.Medium - #11Count business days
Write a Python program to count the working days (Monday to Friday) between two dates.Medium - #12Difference between two times
Write a Python program to find hours and minutes between two datetimes.Easy - #13All dates in a range
Write a Python program to list every date in a week.Easy - #14Timestamps
Write a Python program to convert between a datetime and a Unix timestamp.Easy - #15Convert time zones
Write a Python program to convert 12:00 UTC to Indian Standard Time.Easy - #16Sort date strings
Write a Python program to sort a list of date strings in date order.Easy - #17Day of the year and week number
Write a Python program to get the day of the year and ISO week number of a date.Easy - #18Next Monday
Write a Python program to find the date of the next Monday after a given date.Easy - #19Countdown to an event
Write a Python program that prints the days, hours and minutes until an event.Easy - #20Print a month calendar
Write a Python program to print the calendar of a month.Easy