Answers for "strptime() many format"

0

strptime() many format

from datetime import datetime

def try_parsing_date(text):
    for fmt in ('%Y-%m-%d', '%d.%m.%Y', '%d/%m/%Y'):
        try:
            return datetime.strptime(text, fmt)
        except ValueError:
            pass
    raise ValueError('no valid date format found')
Posted by: Guest on June-26-2020

Python Answers by Framework

Browse Popular Code Answers by Language