Correct the logic for converting to datetime