check if a string can be converted into date or not python

Solutions on MaxInterview for check if a string can be converted into date or not python by the best coders in the world

showing results for - "check if a string can be converted into date or not python"
Liah
18 Feb 2017
1from dateutil.parser import parse
2
3def is_date(string, fuzzy=False):
4    """
5    Return whether the string can be interpreted as a date.
6
7    :param string: str, string to check for date
8    :param fuzzy: bool, ignore unknown tokens in string if True
9    """
10    try: 
11        parse(string, fuzzy=fuzzy)
12        return True
13
14    except ValueError:
15        return False