parser

This module offers a generic date/time string parser which is able to parse most known formats to represent a date and/or time.

Additional resources about date/time string formats can be found below:

dateutil.parser.parse(timestr, parserinfo=None, **kwargs)[source]

Parse a string in one of the supported formats, using the parserinfo parameters.

Parameters:
  • timestr – A string containing a date/time stamp.
  • parserinfo – A parserinfo object containing parameters for the parser. If None, the default arguments to the parserinfo constructor are used.

The **kwargs parameter takes the following keyword arguments:

Parameters:
  • default – The default datetime object, if this is a datetime object and not None, elements specified in timestr replace elements in the default object.
  • ignoretz – Whether or not to ignore the time zone (boolean).
  • tzinfos – A time zone, to be applied to the date, if ignoretz is True. This can be either a subclass of tzinfo, a time zone string or an integer offset.
  • dayfirst – Whether to interpret the first value in an ambiguous 3-integer date (e.g. 01/05/09) as the day (True) or month (False). If yearfirst is set to True, this distinguishes between YDM and YMD. If set to None, this value is retrieved from the current parserinfo object (which itself defaults to False).
  • yearfirst – Whether to interpret the first value in an ambiguous 3-integer date (e.g. 01/05/09) as the year. If True, the first number is taken to be the year, otherwise the last number is taken to be the year. If this is set to None, the value is retrieved from the current parserinfo object (which itself defaults to False).
  • fuzzy – Whether to allow fuzzy parsing, allowing for string like “Today is January 1, 2047 at 8:21:00AM”.
  • fuzzy_with_tokens – If True, fuzzy is automatically set to True, and the parser will return a tuple where the first element is the parsed datetime.datetime datetimestamp and the second element is a tuple containing the portions of the string which were ignored, e.g. “Today is January 1, 2047 at 8:21:00AM” should return (datetime.datetime(2011, 1, 1, 8, 21), (u’Today is ‘, u’ ‘, u’at ‘))
class dateutil.parser.parserinfo(dayfirst=False, yearfirst=False)[source]

Class which handles what inputs are accepted. Subclass this to customize the language and acceptable values for each parameter.

Parameters:
  • dayfirst – Whether to interpret the first value in an ambiguous 3-integer date (e.g. 01/05/09) as the day (True) or month (False). If yearfirst is set to True, this distinguishes between YDM and YMD. Default is False.
  • yearfirst – Whether to interpret the first value in an ambiguous 3-integer date (e.g. 01/05/09) as the year. If True, the first number is taken to be the year, otherwise the last number is taken to be the year. Default is False.
AMPM = [(u'am', u'a'), (u'pm', u'p')]
HMS = [(u'h', u'hour', u'hours'), (u'm', u'minute', u'minutes'), (u's', u'second', u'seconds')]
JUMP = [u' ', u'.', u',', u';', u'-', u'/', u"'", u'at', u'on', u'and', u'ad', u'm', u't', u'of', u'st', u'nd', u'rd', u'th']
MONTHS = [(u'Jan', u'January'), (u'Feb', u'February'), (u'Mar', u'March'), (u'Apr', u'April'), (u'May', u'May'), (u'Jun', u'June'), (u'Jul', u'July'), (u'Aug', u'August'), (u'Sep', u'Sept', u'September'), (u'Oct', u'October'), (u'Nov', u'November'), (u'Dec', u'December')]
PERTAIN = [u'of']
TZOFFSET = {}
UTCZONE = [u'UTC', u'GMT', u'Z']
WEEKDAYS = [(u'Mon', u'Monday'), (u'Tue', u'Tuesday'), (u'Wed', u'Wednesday'), (u'Thu', u'Thursday'), (u'Fri', u'Friday'), (u'Sat', u'Saturday'), (u'Sun', u'Sunday')]
ampm(name)[source]
convertyear(year)[source]
hms(name)[source]
jump(name)[source]
month(name)[source]
pertain(name)[source]
tzoffset(name)[source]
utczone(name)[source]
validate(res)[source]
weekday(name)[source]