Reformat Date
This problem can be solved using Python’s built-in datetime library to handle date conversion. You need to create a date string with the correct format and convert it to the desired format.
Here is the Python code for this problem:
|
|
This code works by first creating a dictionary to map month names to their respective number representations. The input date is then split into day, month, and year components. The day component has its suffix removed and is padded with a leading zero if necessary. The month component is replaced with its corresponding number using the dictionary. Finally, the reformatted date is returned in the ‘YYYY-MM-DD’ format.