I used strptime() with format '%d %a %Y %-Ip%' but it's throwing the error stating "-I" is bad directive.
Asked
Active
Viewed 216 times
0
-
`pd.to_datetime('6 dec 2019 9pm')` – luigigi Dec 16 '19 at 11:25
-
What OS are you on? – roganjosh Dec 16 '19 at 11:25
-
Use `pd.to_datetime(date_col, format='%d %b %Y %I%p')` – Chris Adams Dec 16 '19 at 11:26
2 Answers
0
You have your time format wrong. %-Ip%
is not a valid format (should be %I%p
), and %a
is also incorrect for parsing dec
(should be %b%
).
The following example shows the output with the format %d %b %Y %I%p
:
import time
struct_time = time.strptime("6 dec 2019 9pm", "%d %b %Y %I%p")
print(struct_time)
Output:
time.struct_time(tm_year=2019, tm_mon=12, tm_mday=6, tm_hour=21, tm_min=0, tm_sec=0, tm_wday=4, tm_yday=340, tm_isdst=-1)

Martin
- 16,093
- 1
- 29
- 48
0
You can use datetime
from datetime import datetime
datetime.strptime('6 dec 2019 9pm', '%d %b %Y %I%p')

Bilal Zaib
- 21
- 4