Q:

Convert string into a datetime object using python programming

belongs to collection: Python Date and Time Exercises

0

Convert string into a datetime object

For example, You received the following date in string format. Please convert it into Python’s DateTime object.

Given:

date_string = "Feb 25 2020 4:20PM"

Expected output:

2020-02-25 16:20:00

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Solution:

from datetime import datetime

date_string = "Feb 25 2020  4:20PM"
datetime_object = datetime.strptime(date_string, '%b %d %Y %I:%M%p')
print(datetime_object)

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Subtract a week (7 days) from a given date in Pyt... >>
<< Print current date and time in Python...