In my table, I have different types of dates just with numbers and in this two formats:
yyyy-m-d
yyyy-mm-dd
Some values, as the month for example, don't have the zero in the case of months under 10 and I need it to create a condition to chose elements by the latest date.
I want that all of them have the same format:
yyyy-mm-dd
Any pythonic way to solve that?
For the moment I am using this:
if line.startswith('# Date: '):
#date = 2014-5-28
d = line.strip().split(':')[-1].split('-').replace(' ','')
if len(d[0]) == 4:
year = str(d[0])
elif len(d[1]) < 2:
month = '0'+ str(d[1])
elif len(d[2]< 2):
day = '0'+ str(d[1])
date = year + month + day