XmlDate

class xsdata.models.datatype.XmlDate(year, month, day, offset=None)[source]

Concrete xs:date builtin type.

Represents iso 8601 date format [-]CCYY-MM-DD[Z|(+|-)hh:mm] with rich comparisons and hashing.

Parameters
  • year (int) – Any signed integer, eg (0, -535, 2020)

  • month (int) – Unsigned integer between 1-12

  • day (int) – Unsigned integer between 1-31

  • offset (Optional[int]) – Signed integer representing timezone offset in minutes

replace(year=None, month=None, day=None, offset=True)[source]

Return a new instance replacing the specified fields with new values.

Parameters
Return type

XmlDate

classmethod from_string(string)[source]

Initialize from string with format %Y-%m-%dT%z

Parameters

string (str) –

Return type

XmlDate

classmethod from_date(obj)[source]

Initialize from datetime.date instance.

Warning

date instances don’t have timezone information!

Parameters

obj (date) –

Return type

XmlDate

classmethod from_datetime(obj)[source]

Initialize from datetime.datetime instance.

Parameters

obj (datetime) –

Return type

XmlDate

classmethod today()[source]

Initialize from datetime.date.today()

Return type

XmlDate

to_date()[source]

Return a datetime.date instance.

Return type

date

to_datetime()[source]

Return a datetime.datetime instance.

Return type

datetime

__str__()[source]

Return the date formatted according to ISO 8601 for xml.

Examples:
  • 2001-10-26

  • 2001-10-26+02:00

  • 2001-10-26Z

Return type

str