Python Forum
Datetime strp\delta problems
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Datetime strp\delta problems
#1
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 ,
Reply
#2
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
korenron likes this post
Reply
#3
Thank you!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Store Previous date to calculate delta from today Captain_Wolf 7 3,316 May-08-2020, 06:08 PM
Last Post: SheeppOSU
  TypeError: unsupported operand type(s) for -: 'datetime.datetime' and 'str' findbikash 2 9,626 Sep-18-2019, 08:32 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020