Create convert_str_to_datetime() function to reduce code redundancy