Reading Time: 1 minutes
Convert a date of dd-mm-yyyy format to yyyy-mm-dd format in Python
Write a Regular Expression in Python to convert a date of dd-mm-yyyy format to yyyy-mm-dd format.
Convert a date of dd-mm-yyyy format to yyyy-mm-dd format
import re sourceString = '13-02-2017' print( re.sub('(\d{1,2})-(\d{1,2})-(\d{4})', r'\3-\2-\1', sourceString) ) # '2017-02-13'
To learn more about Regular Expressions in Python, click here.