datetime.strptime parses an input string in the user-specified format into a timezone-naive datetime object:

>>> from datetime import datetime
>>> datetime.strptime('Jun 1 2005  1:33PM', '%b %d %Y %I:%M%p')
datetime.datetime(2005, 6, 1, 13, 33)

To obtain a date object using an existing datetime object, convert it using .date():

>>> datetime.strptime('Jun 1 2005', '%b %d %Y').date()
date(2005, 6, 1)

Links:

  • strptime docs: Python 2, Python 3

  • strptime/strftime format string docs: Python 2, Python 3

  • strftime.org format string cheatsheet

Notes:

  • strptime = "string parse time"
  • strftime = "string format time"
Answer from Patrick Harrington on Stack Overflow
🌐
Python documentation
docs.python.org › 3 › library › datetime.html
datetime — Basic date and time types
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.
🌐
Inventive HQ
inventivehq.com › home › blog › python datetime format: strftime, strptime & date conversion examples
Python Datetime Format: strftime, strptime & Date Conversion Examples
November 6, 2025 - For example, the date string "7/11/2019" would use the mask "%m/%d/%Y" to indicate month/day/year format separated by forward slashes. The strptime() function (String Parse Time) is your primary tool for converting date strings into datetime objects.
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-string-to-datetime-strptime
How To Convert a String to a datetime Object in Python | DigitalOcean
December 13, 2024 - The ValueError messages that you get when you use the strptime() method clearly explain the root causes of the parsing errors. The following example demonstrates some common errors, such as extra data and a format mismatch: from datetime import datetime import time datetime_str = '09/19/18 ...
🌐
Statology
statology.org › home › how to parse dates from text in python
How to Parse Dates from Text in Python
August 5, 2024 - The most common way to parse dates in Python is using the strptime() function from the datetime module.
🌐
Learn By Example
learnbyexample.org › how-to-convert-string-to-date-time-in-python-using-strptime
How to Convert String to Date/Time in Python Using strptime() - Learn By Example
April 23, 2024 - When parsing locale-specific dates, always ensure your environment’s locale settings match the date string’s language, or use a module like locale to handle locale settings in Python. from datetime import datetime import locale # Set French locale locale.setlocale(locale.LC_TIME, 'fr_FR') # Locale-specific date format datetime_string = "15 Janvier 2024" datetime_object = datetime.strptime(datetime_string, "%d %B %Y") print(datetime_object) # Output: 2024-01-15 00:00:00
Find elsewhere
🌐
Dataquest
dataquest.io › blog › python-datetime-tutorial
Python Datetime Tutorial: Manipulate Times, Dates, and Time Spans
January 5, 2026 - We touched briefly on strftime() ... work in Python. strptime() is the method we used before, and you’ll recall that it can turn a date and time that’s formatted as a text string into a datetime object, in the following format: ... format − the specific formatting of the time in the string, so that strptime() can parse it ...
🌐
LabEx
labex.io › tutorials › python-how-to-parse-date-and-time-information-from-a-string-in-python-417951
How to parse date and time information from a string in Python | LabEx
import datetime ## Example: Creating a datetime object date_time = datetime.datetime(2023, 5, 1, 12, 30, 0) print(date_time) ## Output: 2023-05-01 12:30:00 ## Example: Formatting a datetime object as a string formatted_date = date_time.strftime("%Y-%m-%d %H:%M:%S") print(formatted_date) ## Output: 2023-05-01 12:30:00 · By understanding the different date and time formats and how to work with them in Python, you can effectively handle a wide range of date and time-related tasks in your applications. One common task when working with dates and times in Python is parsing date and time information from string representations.
🌐
Oreate AI
oreateai.com › blog › unlocking-pythons-time-converting-strings-to-datetime-objects › bfe1726d36c1aa0d922c75d3aca4206a
Unlocking Python's Time: Converting Strings to Datetime Objects - Oreate AI Blog
February 9, 2026 - Learn how to convert string representations of dates and times into Python datetime objects using `datetime.strptime()` and the `dateutil` library for unknown formats.
🌐
DataCamp
datacamp.com › tutorial › converting-strings-datetime-objects
Convert String to DateTime in Python: Complete Guide with Examples | DataCamp
June 8, 2018 - from dateutil.parser import parse # Automatically infers the format date_obj = parse("March 1, 2023 9:30 AM") print(date_obj) This is especially useful when dealing with unpredictable or inconsistent date formats. For timezone-aware datetime handling, Python offers two popular options:
🌐
Python Morsels
pythonmorsels.com › converting-a-string-to-a-datetime
Converting a string to a datetime - Python Morsels
September 30, 2024 - Trey Hunner 4 min. read • Python 3.10—3.14 • Sept. 30, 2024 ... Copied to clipboard. Tags ... You need the strptime class method. That's the easy part. The hard part is figuring out which format string you need to specify to parse your date string properly. Here's an example of the strptime class method in action: >>> from datetime import datetime >>> datetime.strptime("Jun 1 2005 1:33PM", "%b %d %Y %I:%M%p") datetime.datetime(2005, 6, 1, 13, 33)
🌐
Luasoftware
code.luasoftware.com › tutorials › python › python-parse-string-to-date
Python Parse String to datetime
August 7, 2019 - date_str = 'Sat Jul 11 21:09:55 2019'd = dateutil_parser.parse(date_str) ... date_str = '2019-08-07T15:36:11.618911Z'# ordate_str = '2019-08-07T15:36:11.618Z'# ordate_str = '2019-08-07T15:36:11Z' If you know the miliseconds decimals and whether it contains timezone or not · import datetimedate_str = '2019-08-07T15:36:11Z'datetime.datetime.strptime(date_str, "%Y-%m-%dT%H:%M:%S%z")
🌐
Python
docs.python.org › 3 › library › time.html
time — Time access and conversions
The format parameter uses the same directives as those used by strftime(); it defaults to "%a %b %d %H:%M:%S %Y" which matches the formatting returned by ctime(). If string cannot be parsed according to format, or if it has excess data after parsing, ValueError is raised.
🌐
dateutil
dateutil.readthedocs.io › en › stable › parser.html
parser — dateutil 3.9.0 documentation
Returns a datetime.datetime object or, if the fuzzy_with_tokens option is True, returns a tuple, the first element being a datetime.datetime object, the second a tuple containing the fuzzy tokens. ... ParserError – Raised for invalid or unknown string formats, if the provided tzinfo is not in a valid format, or if an invalid date would be created.
🌐
alpharithms
alpharithms.com › home › tutorials › converting between strings and datetime objects in python
Converting Between Strings and Datetime Objects in Python - αlphαrithms
June 17, 2022 - Python’s datetime module converts between strings and datetime objects using a unique symbolic syntax. These symbols can be passed in string format to the datetime module via the strftime and strptime functions and control the format in which a datetime object is either parsed from a string ...
🌐
Reddit
reddit.com › r/learnpython › parse date string: best way to parse string containing utc
r/learnpython on Reddit: Parse date string: Best way to parse string containing UTC
January 19, 2022 -

Hi.

Consider this text string: 2021-01-01 01:01:00 UTC.

What's the best way of parsing this into a date object in Python 3? I could remove the "UTC" from the text, and then use something like datetime.strptime(date_string, format), but isn't there an easier way, like doesn't Python already have support for parseing strings like these?

🌐
PyPI
pypi.org › project › DateTime
DateTime · PyPI
DateTime objects may be converted to integer, long, or float numbers of days since January 1, 1901, using the standard int, long, and float functions (Compatibility Note: int, long and float return the number of days since 1901 in GMT rather than local machine timezone). DateTime objects also provide access to their value in a float format usable with the Python time module, provided that the value of the object falls in the range of the epoch-based time module.
      » pip install DateTime
    
Published   Nov 25, 2025
Version   6.0
🌐
GeeksforGeeks
geeksforgeeks.org › python › convert-string-to-datetime-in-python-with-timezone
Convert string to datetime in Python with timezone - GeeksforGeeks
July 23, 2025 - Explanation: arrow.get(s) parses the date-time string s into an Arrow datetime object with timezone support, without requiring an explicit format string, providing a clean and user-friendly API.
🌐
GeeksforGeeks
geeksforgeeks.org › python › converting-string-yyyy-mm-dd-into-datetime-in-python
Converting string into DateTime in Python - GeeksforGeeks
July 23, 2025 - Explanation: Here, we passed the ... object. datetime.strptime() method, part of Python's datetime module, efficiently converts a date string into a DateTime object when the exact format is known, requiring a format ...