The time is given in string for eg "23:20". However in my function I need to compare times for which I gotta convert these to time format
I tried strptime() and it works with 12 hour format for eg when I enter "12:00PM"
Possible Duplicate of [https://stackoverflow.com/questions/19229190/how-to-convert-am-pm-timestmap-into-24hs-format-in-python]
Code that works from there
%H is the 24 hour clock, %I is the 12 hour clock and when using the 12 hour clock, %p qualifies if it is AM or PM.
from datetime import datetime m2 = '1:35 PM' in_time = datetime.strptime(m2, "%I:%M %p") out_time = datetime.strftime(in_time, "%H:%M") print(out_time) 13:35
strptime. There are a couple different things to consider