🔵 🔵 🔵


Primary

၊၊||၊|။

date.strptime() ⚬|Documentation|1st|20260106140430-00-⌔

datetime — Basic date and time types — Python 3.14.2 documentation#datetime.date.strptime

method classdate.strptime(date_string, format)

Return a date corresponding to date_string, parsed according to format. This is equivalent to:

date(﹡(time.strptime(date_string, format)[0:3]))

ValueError is raised if the date_string and format can’t be parsed by time.strptime() or if it returns a value which isn’t a time tuple. See also strftime() and strptime() behavior and date.fromisoformat().

Note: If format specifies a day of month without a year a DeprecationWarning is emitted. This is to avoid a quadrennial leap year bug in code seeking to parse only a month and day as the default year used in absence of one in the format is not a leap year. Such format values may raise an error as of Python 3.15. The workaround is to always include a year in your format. If parsing date_string values that do not have a year, explicitly add a year that is a leap year before parsing:

>>> import datetime as dt
>>> date_string = "02/29"
>>> when = dt.date.strptime(f"{date_string};1984", "%m/%d;%Y")  # Avoids leap year bug.
>>> when.strftime("%B %d")
'February 29'

Added in version 3.14.

Class attributes:

Printed 2026-06-28.

(echo:: @ )

Link to original

Secondary

• • •