How to use date with this format 01/01/2020 00:01

HI,

I just can’t sue and make calculations like this one:

time_1 = datetime.strptime(‘01/01/2020 00:01’,’%d/%m/%y %H:%M’)
time_2 = datetime.strptime(‘01/01/2020 00:02’,’%d/%m/%y %H:%M’)

time_interval = time_2 - time_1
print(time_interval)

raise ValueError("time data %r does not match format %r" %
ValueError: time data '01/01/2020 00:01' does not match format '%d/%m/%y %H:%M'

I really don’t know what to do.
Can sombody check it please?

you need the upper case “Y”

>>> datetime.datetime.strptime("01/01/2020 00:01", "%d/%m/%Y %H:%M")
datetime.datetime(2020, 1, 1, 0, 1)
1 Like

Hi cat and welcome.

You may find this link of use; just one of my ‘go to’ sites.

1 Like

@root-11 and @rob42 Thank you so much