How to convert string to date in python with different algorithms

0 votes
In python it is possible to convert string to date format but there are different algorithms and methods.
Jun 21, 2020 in Python by pagarsach
• 160 points
889 views

1 answer to this question.

0 votes

Hello @ pagarsach,

You can convert a string to date object using the strptime function.

Provide the date string and the format in which the date is specified. 

Example:

import datetime
date_str = '30062020' # The date - 30 Jun 2020
format_str = '%d%m%Y' # The format
datetime_obj = datetime.datetime.strptime(date_str, format_str)
print(datetime_obj.date())

Output

This will give the output −

30-06-2020

Hope it helps!!

Thank You!!

answered Jun 30, 2020 by Niroj
• 82,840 points

Related Questions In Python

0 votes
1 answer

How to convert date string to date object in python?

Use this :-  >>> datetime.datetime.strptime('24052010', "%d%m%Y").date() datetime.date(2010, 5, 24) Hope ...READ MORE

answered Oct 22, 2018 in Python by Priyaj
• 58,020 points
11,233 views
0 votes
1 answer

How to parse date/time string with timezone abbreviated name in Python?

The parse() function in dateutil can't handle ...READ MORE

answered Nov 27, 2018 in Python by Nymeria
• 3,560 points
2,259 views
0 votes
1 answer

How to convert datetime.date to UTC timestamp in Python

In Python 3 (< 3.3) From the docs ...READ MORE

answered Oct 31, 2018 in Python by Priyaj
• 58,020 points
9,936 views
0 votes
1 answer

How to check if a string ends with a character in python?

You can use the endswith method. It checks ...READ MORE

answered Apr 5, 2019 in Python by Srisha
2,876 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,434 views
0 votes
1 answer
0 votes
1 answer
+1 vote
12 answers
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP