Skip to main content

parse_datetime

Parse a string and return a datetime.datetime.

This function supports time zone offsets. When the input contains one, the output uses a timezone with a fixed offset from UTC.

Raise ValueError if the input is well formatted but not a valid datetime. Return None if the input isn't well formatted.

def parse_datetime(
value: str
) - > datetime.datetime | None

Parse a string and return a datetime.datetime. This function supports time zone offsets. When the input contains one, the output uses a timezone with a fixed offset from UTC. Raise ValueError if the input is well formatted but not a valid datetime. Return None if the input isn't well formatted.

Parameters

NameTypeDescription
valuestrThe date-time string to be parsed, typically in ISO 8601 format or a similar supported pattern.

Returns

TypeDescription
`datetime.datetimeNone`