Answers for "strftime python multiple formats"

0

strftime python multiple formats

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