+2 votes
2 views
in Python by (3.5k points)
edited by

I want to covert a large complex date-time string into proper datetime fields in a database,  Can someone tell me a short method to do it, I am attaching a simple example for ref.

    Jun 24 2019  8:04PM
    Sep 28 1999 10:00AM

I can't use SQL.

2 Answers

0 votes
by (46.1k points)
edited by

It's a very easy task to do, just follow this syntax to get your result:

from datetime import datetime

datetime_object = datetime.strptime('Jun 4 2019  3:25PM', '%b %d %Y %I:%M%p')

String used above i.e. datetime.strptime can handle all kinds of Formats. 

Hope this helps.

0 votes
by (107k points)

You can use the third party dateutil library:

from dateutil import parser

dt = parser.parse("Aug 28 1999 12:00AM")

You can use the following video tutorials to clear all your doubts:-

Related questions

+2 votes
2 answers
asked May 23, 2019 in Python by Anvi (10.2k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jul 3, 2019 in Python by Sammy (47.8k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...