0

I have the following problem. I am checking for an expiration date each time having a different format. One of them is 'Dec 31, 2019 12:00 AM', other - '2019-12-31 11:00' and last (but I excpect more other values) - 'Thu Dec 31 00:00:00 EEST 2019'. I am trying with datetime.strptime(dateToFormat, fmt).strftime("%Y%m%d") but if I need to pass all the fmt it will neve end as I don't know all the formats that could be received.

The showstopper for me is that I cannot use additional modules in python so I am currently stuck with the datetime module only...

Somebody has a clue?

Thanks in advance!

infinity
  • 23
  • 5
  • Do you have a short list of potential formats, or could it be essentially any format? – user1558604 Dec 12 '19 at 14:07
  • 3
    This may be a duplicate of https://stackoverflow.com/questions/23581128/how-to-format-date-string-via-multiple-formats-in-python – Kredns Dec 12 '19 at 14:12
  • Yes, thank you very much! – infinity Dec 12 '19 at 15:32
  • Does this answer your question? [How to format date string via multiple formats in python](https://stackoverflow.com/questions/23581128/how-to-format-date-string-via-multiple-formats-in-python) – infinity Dec 12 '19 at 15:34

1 Answers1

0

I can see that you have clearly mentioned that you can use only datetime module of python! Incase if you have any option of using either dateutil or datefinder modules, you can use this answer

McLovin
  • 555
  • 8
  • 20
  • Yes, I used them before (the dateutil.parser) but I was forbidden :) Nevertheless, there is a useful suggestion in the answer you've provided me. Maybe finally I will use the "date_patterns" approach... Thanks! – infinity Dec 12 '19 at 15:31