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 | |
---|---|
%Y | 4 digit year (0000-9999) |
%m | 2 digit month (1-12) |
%d | 2 digit day (1-31) |
%H | 2 digit hour (0-23) |
%M | 2 digit minute (0-59) |
%S | 2 digit second (0-59) |
This exercise is part of the course
Working with Dates and Times in Python
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# 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)