Python 3.7+datetimefunction
datetime.date.fromisoformat()
date
Parse an ISO 8601 string ('YYYY-MM-DD') into a date object — the inverse of .isoformat(); raises ValueError on a malformed string.
Syntax
from datetime import date
date.fromisoformat('2024-01-01')
It is not a general-purpose date parser: '15.03.2024' or '03/15/2024' raise ValueError — for arbitrary layouts use datetime.strptime with a format string. Before Python 3.11 it accepted only the exact YYYY-MM-DD spelling; since 3.11 it handles most ISO forms, including '20240315' and week dates such as '2024-W11-5'.
Examples
from datetime import date
d = date.fromisoformat('2024-03-15')
print(d) # → 2024-03-15
print(d.isoformat()) # → 2024-03-15 (обратно в строку)
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy