In this Python string tutorial, you will learn how to convert string to DateTime in Python.
# Import datetime module import datetime # Create a string S = "2022-10-15 05:35:55" # Convert string into datetime D = datetime.datetime.strptime(S, "%Y-%m-%d %H:%M:%S") # Print datetime print(D) # Display the type of D print(type(D))
Output:
2022-10-15 05:35:55 <class 'datetime.datetime'>