def parse_date ( s ) : if isinstance ( s , ( datetime . datetime , datetime . date ) ) : return s try : from dateutil . parser import parse except ImportError : parse = lambda d : datetime . datetime . strptime ( d , "%Y-%m-%d" ) return parse ( s )
python parse date string to date object
Parse a date using dateutil . parser . parse if available falling back to datetime . datetime . strptime if not
def parse_date(s):
    """
    Parse a date using dateutil.parser.parse if available,
    falling back to datetime.datetime.strptime if not
    """
    if isinstance(s, (datetime.datetime, datetime.date)):
        return s
    try:
        from dateutil.parser import parse
    except ImportError:
        parse = lambda d: datetime.datetime.strptime(d, "%Y-%m-%d")
    return parse(s)