Dateparser

1.4.0 · active · verified Sat Mar 28

Dateparser is a Python library (v1.4.0) designed to parse dates from various formats, including natural language and localized strings, often found on web pages. It aims to simplify datetime string conversion, timezone handling, and ambiguous date resolution. The library has an active development cycle with minor versions released every few months, frequently adding new language support and parsing features.

Warnings

Install

Imports

Quickstart

The most common way to parse dates is using the `dateparser.parse()` function. It automatically detects formats and languages, and can be configured with settings for more control, such as handling relative dates or specific timezones.

import dateparser
from datetime import datetime

# Basic parsing
date_obj1 = dateparser.parse('12/12/12')
print(f"'12/12/12' parsed as: {date_obj1}")

# Parsing a relative date
date_obj2 = dateparser.parse('2 days ago')
print(f"'2 days ago' parsed as: {date_obj2}")

# Parsing a date with specific language settings
date_obj3 = dateparser.parse('Martes 21 de Octubre de 2014', languages=['es'])
print(f"'Martes 21 de Octubre de 2014' (Spanish) parsed as: {date_obj3}")

# Parsing with timezone preference
date_obj4 = dateparser.parse('August 14, 2015 EST', settings={'TIMEZONE': 'America/New_York', 'RETURN_AS_TIMEZONE_AWARE': True})
print(f"'August 14, 2015 EST' with timezone preference: {date_obj4}")

view raw JSON →