Add a loop to detect whether the DD and MM need to be swapped