-4

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

KowaiiNeko
  • 327
  • 6
  • 17

1 Answers1

2

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.

iz_
  • 15,923
  • 3
  • 25
  • 40