Dates and times Format

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[2]
start_date = dt.datetime.strptime(start_date, date_format)
row[2] = start_date

Why when I make as format %m/ i received %m- ??

2015-01-06 09:30:00
2015-01-06 09:30:00
2015-01-06 09:30:00


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 newdate and 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!