Editor

Parse a Date String

Intermediate · 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 lesson

Parse the string '15-06-2024' into a datetime object using strptime with the format '%d-%m-%Y'. Then print it reformatted as 'June 15, 2024' using strftime.

from datetime import datetime
date_string = '15-06-2024'
# Parse and reformat

More datetime exercises

All Python exercises · 50 practice problems · Standard Library Essentials quiz