Convert string to DateTime Python

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

# Display the type of D


2022-10-15 05:35:55
<class 'datetime.datetime'>

Free learning resources: AiHintsCodeAllow

Leave a Comment

Your email address will not be published.