Hi Dataquest folks!
I do not understand why I give the date format with / and I receive - between the numbers!
date_format = “%m/%d/%y %H:%M”
for row in potus:
start_date = row
start_date = dt.datetime.strptime(start_date, date_format)
row = start_date
Why when I make as format %m/ i received %m- ??
Hi @ANDI. The
date_format is passed into the
datetime.strptime() function so that the function knows how the date already exists in the data. Before we use it, the dates and times are strings. When we pass the information into
datetime.strptime(), it converts the strings into datetime objects. With datetime objects, we’re able to do some pretty useful calculations that would not be possible while the dates are in string format.
In the screenshot below, I have the variables
origdate where you can see the difference in how the data is stored after running the code.
If we want to display the date and time in a specific format, we’ll be able to use
datetime.strftime(), which I think you learn about in the next screen.
I hope that makes sense!