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
187 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,720 points

Related Questions In Python

0 votes
1 answer

How to convert date string to date object in python?

Use this :-  >>> datetime.datetime.strptime('2405201 ...READ MORE

answered Oct 22, 2018 in Python by Priyaj
• 58,120 points
9,241 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,520 points
844 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,120 points
8,126 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 4, 2019 in Python by Srisha
1,216 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 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 2,033 views
0 votes
0 answers
0 votes
1 answer
+1 vote
12 answers