1

I have a string which may contain date into any of the below format

20200618
18-june-2020

Could someone please help me in how to obtain the date from the string? Thanks

Amiclone
  • 388
  • 2
  • 11
  • I am not sure whether there is a library that does it by itself, but if those are the only two formats, you can use regexp to check what is your date's format and then convert it – Yaroslav Fyodorov Nov 01 '20 at 12:31

1 Answers1

2

dateutil's parser can help:

from dateutil import parser

for d in ["20200618", "18-june-2020"]:
    print(parser.parse(d))
    
2020-06-18 00:00:00
2020-06-18 00:00:00
FObersteiner
  • 22,500
  • 8
  • 42
  • 72