Python @ DjangoSpin

PyPro #80 Convert a date of dd-mm-yyyy format to yyyy-mm-dd format

Buffer this pageShare on FacebookPrint this pageTweet about this on TwitterShare on Google+Share on LinkedInShare on StumbleUpon
Reading Time: 1 minutes

Convert a date of dd-mm-yyyy format to yyyy-mm-dd format in Python

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.


See also:

Buffer this pageShare on FacebookPrint this pageTweet about this on TwitterShare on Google+Share on LinkedInShare on StumbleUpon

Leave a Reply