Python Forum

Full Version: Datetime strp\delta problems
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello ,
I think I'm missing something

I have a string and I want to make it a datetime object
I have found this
 StartDate = datetime.strptime(StartDate, '%d/%m/%Y-%H:%M:%S')
then I want to add to it 5 min
EndDate = StartDate + datetime.timedelta(minutes=5)
I'm using
from datetime import datetime
import datetime
but I get an error of :
AttributeError: module 'datetime' has no attribute 'strptime'
how can it be ?

when I remove the "import datetime" I get this error
AttributeError: type object 'datetime.datetime' has no attribute 'timedelta'
so what am I missing?

Thanks ,
This works
import datetime

test_date = '13/06/2021-11:11:11'
start_date = datetime.datetime.strptime(test_date, '%d/%m/%Y-%H:%M:%S')
print(start_date)
end_date = start_date + datetime.timedelta(minutes=5)
print(end_date)
Output:
2021-06-13 11:11:11 2021-06-13 11:16:11
Thank you!