To change string to datetime format

Asked 1 years ago, Updated 1 years ago, 100 views

on the list "Jun 1 2005 1:33PM" "Aug 28 1999 12:00AM"

There are a lot of the same strings You want to replace all of this string with datetime format and save it to DB.

How do I change a string to datetime?

django python datetime

2022-09-21 21:31

1 Answers

Write strptime

import datetime
a = "Jun 1 2005  1:33PM"

result = datetime.datetime.strptime(a,"%b %d %Y %I:%M%p")
print (result)

You can write with .

as %d, %Y in appropriate format Match direct.


2022-09-21 21:31

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.