You can use Python module datetime to convert a string into DateTime object in Python as shown in the below example –
1 2 3 4 5 6 7 8 9 10 11 12 |
from datetime import datetime mytime = "Oct 10 2021 5:15PM" mytimeobject = datetime.strptime(mytime, '%b %d %Y %I:%M%p') print(mytimeobject) print(type(mytimeobject)) ## Returns ## 2021-10-10 17:15:00 ## |