I have a variable '2019-05-30 21:01:09'
that needs to be converted into 2019-05-30 21:01:09
. What is the best way to go about this.
Asked
Active
Viewed 26 times
2 Answers
1
from datetime import datetime
strToDate = datetime.strptime('2019-05-30 21:01:09','%Y-%m-%d %H:%M:%S')
strptime() allows for the conversion of string to date time object provided that you give the format the function should expect as the second argument

Thomas Burke
- 1,105
- 9
- 20
0
You can using datetime library
from datetime import datetime
datetime.strptime('2019-05-30 21:01:09', '%Y-%m-%d %H:%M:%S')
https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior

Peter
- 120
- 1
- 8