- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to convert Python date string mm/dd/yyyy to datetime?
In Python, 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 = '29/12/2017' # The date - 29 Dec 2017 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 −
2017-12-29
Advertisements