{"id":9952,"date":"2021-07-08T11:12:04","date_gmt":"2021-07-08T05:42:04","guid":{"rendered":"https:\/\/pynative.com\/?p=9952"},"modified":"2021-12-05T10:22:57","modified_gmt":"2021-12-05T04:52:57","slug":"python-string-to-datetime-strptime","status":"publish","type":"post","link":"https:\/\/pynative.com\/python-string-to-datetime-strptime\/","title":{"rendered":"Python String to DateTime using strptime()"},"content":{"rendered":"\n
In this tutorial, we’ll see how to parse a string to a datetime using the In some cases, date and time could be passed as a string object. To convert a string into a strptime()<\/code> with the various standard date formatting codes available in Python. In addition, we will see similar methods available in the other modules for converting a string to a
date<\/code> or
time<\/code> object.<\/p>\n\n\n\n
Table of contents<\/h2>
Steps to Convert String to DateTime in Python<\/h2>\n\n\n\n
datetime<\/code> object, we can use the
strptime()<\/code> function of a datetime module.
For example, you may need to convert a numerical string like 13-05-2021<\/strong> to a datetime<\/code> object. or you want to convert string representing dates like Monday, 13 May, 2021<\/strong> to a
datetime<\/code> object.
The below steps shows how to convert a string representing a date to a datetime object<\/p>