
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 extract date from a string in Python?
You need to know the format of date that can be there in the string in order to extract it. You can simply use a regular expression to extract the date and "datetime.datetime.strptime" to parse the date. For example, If you have the date in a string in the format YYYY-MM-DD, you can use the following code to extract and parse this date,
Example
import re, datetime s = "I have a meeting on 2018-12-10 in New York" match = re.search('\d{4}-\d{2}-\d{2}', s) date = datetime.datetime.strptime(match.group(), '%Y-%m-%d').date() print date
Output
This will give the output −
2018-12-10
- Related Questions & Answers
- How to extract date from string in MySQL?
- How to extract numbers from a string in Python?
- How to extract numbers from a string using Python?
- How to extract a substring from inside a string in Python?
- How to extract date from text using Python regular expression?
- Extract decimal numbers from a string in Python
- How to extract data from a string with Python Regular Expressions?
- Python – How to Extract all the digits from a String
- Python – Extract Percentages from String
- How to extract characters from a string in R?
- Python Regex to extract maximum numeric value from a string
- How to extract multiple integers from a String in Java?
- How to extract words from a string vector in R?
- Extract Numeric Date Value from Date Format in MySQL?
- Extract only characters from given string in Python
Advertisements