I have a date value 20130312
and I would like to convert it into a format like 2013-03-12
or a similar format
I've tried looking into the datetime
library but could not find a solution.
Thanks in advance
I have a date value 20130312
and I would like to convert it into a format like 2013-03-12
or a similar format
I've tried looking into the datetime
library but could not find a solution.
Thanks in advance
I think you are looking for datetime.strptime
:
from datetime import datetime
print(datetime.strptime('20130312', '%Y%m%d'))
For info on the pattern used, see here.