'Strptime() function won't give full python datetime
I have the following datetime which I'm trying to convert into a datetime object.
BEGINDATE = '20211121 09:00:00.000'
start_date = datetime.strptime(BEGINDATE, "%Y%m%d %H:%M:%S.%f")
I expect to see an output like when I run datetime.now(), i.e.
datetime.datetime(2022, 4, 11, 9, 28, 45, 447007)
Instead, I get the following
datetime.datetime(2021, 11, 21, 9, 0)
It cuts out two of the time arguments and also displays the minutes as 0 rather than 00. Have I formatted it wrong?
Solution 1:[1]
I you try with non zero values like this:
BEGINDATE = '20211121 09:01:02.120'
start_date = datetime.strptime(BEGINDATE, "%Y%m%d %H:%M:%S.%f")
you get:
datetime.datetime(2021, 11, 21, 9, 1, 2, 120000)
so the the script is correct and the problem is in the data.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Alessandro Togni |
