Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Python by (45.3k points)

How do I convert a string to a date object in python?

The string would be: "24052010" (corresponding to the format: "%d%m%Y")

I don't want a datetime.datetime object, but rather a datetime.date.

1 Answer

0 votes
by (16.8k points)

You can use strptime in the datetime package of Python:

>>> datetime.datetime.strptime('24052010', "%d%m%Y").date()

datetime.date(2010, 5, 24)

Related questions

0 votes
1 answer
asked Jul 31, 2019 in Python by Eresh Kumar (45.3k points)
0 votes
1 answer
asked Jul 24, 2019 in Python by Eresh Kumar (45.3k points)
0 votes
1 answer
asked Jul 23, 2019 in Python by Eresh Kumar (45.3k points)
0 votes
1 answer
asked Jul 3, 2019 in Python by Sammy (47.6k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.2k users

Browse Categories

...