{"id":6155,"date":"2021-05-16T10:43:26","date_gmt":"2021-05-16T05:13:26","guid":{"rendered":"https:\/\/python-programs.com\/?p=6155"},"modified":"2021-11-22T18:42:37","modified_gmt":"2021-11-22T13:12:37","slug":"python-string-to-datetime-or-date-object","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-string-to-datetime-or-date-object\/","title":{"rendered":"Python: String to datetime or date object"},"content":{"rendered":"

String to datetime or date object in Python.<\/h2>\n

We will see in this article how to convert different format string to a DateTime or date object. We will do so using a function provided by Python\u2019s date-time module to change string into a datetime object i.e. strptime( )<\/code><\/p>\n

Syntax-<\/pre>\n

datetime.strptime(datetime_str, format):<\/em><\/p>\n

Arguments:<\/p>\n