datetime str day of year python code example Example: how to convert string to datetime import datetime datetime.datetime.strptime(date_string, format)