Aan de slagGa gratis aan de slag

Turning strings into datetimes

When you download data from the Internet, dates and times usually come to you as strings. Often the first step is to turn those strings into datetime objects.

In this exercise, you will practice this transformation.

Reference
%Y4 digit year (0000-9999)
%m2 digit month (1-12)
%d2 digit day (1-31)
%H2 digit hour (0-23)
%M2 digit minute (0-59)
%S2 digit second (0-59)

Deze oefening maakt deel uit van de cursus

Working with Dates and Times in Python

Cursus bekijken

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Import the datetime class
from datetime import datetime

# Starting string, in YYYY-MM-DD HH:MM:SS format
s = '2017-02-03 00:00:01'

# Write a format string to parse s
fmt = '____'

# Create a datetime object d
d = datetime.____(____, ____)

# Print d
print(d)
Code bewerken en uitvoeren