Sort Events by Date
Advanced · Write the code · from Python datetime: Dates, Times, Timezones, and Calculations
From the lesson: Python datetime: Dates, Times, Timezones, and Calculations
Think about your phone. It shows the current time, tracks your calendar events, and reminds you about birthdays. Behind the scenes, all of that runs on date and time calculations.
Read the lessonGiven three date strings in '%Y-%m-%d' format, parse them, sort them from earliest to latest, and print each one formatted as '%B %d, %Y' on its own line.
Dates: '2024-12-25', '2024-07-04', '2024-10-31'
from datetime import datetime
date_strings = ['2024-12-25', '2024-07-04', '2024-10-31']
# Parse, sort, and print formatted
More datetime exercises
- Create and Display a DateBeginner
- Calculate Days Between DatesBeginner
- Add Two Weeks to a DateIntermediate
- Parse a Date StringIntermediate
- Predict the Date OutputIntermediate
All Python exercises · 50 practice problems · Standard Library Essentials quiz