You can use the datetime library in Python to convert the date from one format to another. Here's an example code snippet:
main.py173 chars7 lines
Output:
main.py9 chars2 lines
Explanation:
strptime method is used to parse the original date string into a datetime object.%d represents the day of the month (without zero padding).%B represents the full month name (e.g. 'May').%Y represents the year.strftime method is used to format the datetime object into a new date string.%-d and %-m represent the day and month without zero padding.Note that the - symbol is used to remove the zero padding in the day and month fields. This syntax works on Unix systems, but if you're running the code on a Windows system you will need to use a different format code (such as #d and #m).
gistlibby LogSnag