Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use dateparser.parse() for a human-readable date string, then check whether it returned a value: successful parses return a Python datetime, while unsuccessful parses return None. For dependable results, make ambiguous date order, timezone assumptions, relative-date reference time, and missing date components explicit instead of relying on automatic interpretation.

Parse a date string with dateparser

The simplest approach is to import parse and pass it a string. The following example handles the return value before using it:

from dateparser import parse

text = "March 15, 2024 2:30 PM"
value = parse(text)

if value is None:
    raise ValueError(f"Could not parse date: {text!r}")

print(value)

A successful result is a datetime; a failed parse is None. Do not assume the input was understood merely because the function returned without raising an exception. The library is designed for human-readable absolute and relative dates, timestamps, and localized forms, but its flexibility means an application should validate the result against its own requirements. The official overview advises using valid date strings without unrelated words or numbers and providing known language or locale information when possible (dateparser documentation, version 1.4.3).

Install and import

In an environment where the package is not installed, install it with python -m pip install dateparser. Then choose either import dateparser and call dateparser.parse(...), or import the function directly with from dateparser import parse. The examples below use the direct import.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

Handle failure at the application boundary

Decide what invalid input means for your program: reject the record, ask the user to correct it, or record a validation error. Avoid substituting a default date silently; that can turn malformed input into a plausible but incorrect timestamp.

Make known formats and languages explicit

If you know how a source formats dates, pass a format string through date_formats. If you know the language or locale, supply it with languages or locales. The parser tries supplied formats in turn while taking the language or locale information into account. Explicit inputs reduce the amount the parser must infer; they do not remove the need to check the returned value. See the package API reference.

from dateparser import parse

value = parse(
    "15 March 2024",
    date_formats=["%d %B %Y"],
    languages=["en"],
)

if value is None:
    raise ValueError("Input did not match the expected date")

Use the format matching the actual input, rather than adding speculative alternatives simply to make a parse succeed. If your application receives inputs from a known source, keep that source’s expected format and language close to the parsing code so the assumptions remain reviewable.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Control ambiguous numeric date order

A string such as 02-03-2016 can mean February 3 or March 2. The documented default date order is MDY, but locale preferences can take precedence when PREFER_LOCALE_DATE_ORDER is enabled. For example, the settings documentation shows French input being interpreted as DMY despite an explicit MDY setting. To enforce an application policy, set both the desired DATE_ORDER and PREFER_LOCALE_DATE_ORDER to False (settings reference, version 1.4.3).

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
from dateparser import parse

value = parse(
    "02-03-2016",
    settings={
        "DATE_ORDER": "DMY",
        "PREFER_LOCALE_DATE_ORDER": False,
    },
)

if value is None:
    raise ValueError("Could not parse date")

Do not assume that an English-language input identifies its country or date convention. When a numeric date is ambiguous, use a source-specific policy, or reject the input and request an unambiguous representation.

Set timezone behavior deliberately

Timezone configuration answers two different questions: what zone to assign to an input that lacks an explicit zone, and whether to convert the result to another zone. The TIMEZONE setting supplies a zone; TO_TIMEZONE requests conversion; and RETURN_AS_TIMEZONE_AWARE controls awareness in documented cases. Inputs containing an explicit timezone indication or offset should also be handled deliberately. Check the result’s tzinfo and ensure the resulting instant has the meaning your application expects.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
from dateparser import parse

value = parse(
    "January 12, 2012 10:00 PM",
    settings={
        "TIMEZONE": "UTC",
        "RETURN_AS_TIMEZONE_AWARE": True,
    },
)

if value is None:
    raise ValueError("Could not parse date")
if value.tzinfo is None:
    raise ValueError("Expected a timezone-aware datetime")

This example asks for a UTC-aware result for input without an offset. It is an explicit assumption, not information contained in the original string. If the input identifies a different source timezone, configure and verify that behavior for the actual input rather than treating UTC as universally correct. The documented timezone options and examples are in the settings reference.

Make relative and incomplete dates reproducible

Relative expressions such as “tomorrow” depend on when they are parsed. Set RELATIVE_BASE when repeated or historical interpretation needs a stable reference point. Partial inputs, such as a month and year without a day, also require a policy; PREFER_DAY_OF_MONTH supports current, first, or last. These settings supply assumptions for missing information; they do not recover facts the string never stated.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
from datetime import datetime
from dateparser import parse

reference = datetime(2024, 3, 15, 12, 0)
value = parse(
    "tomorrow",
    settings={"RELATIVE_BASE": reference},
)

if value is None:
    raise ValueError("Could not parse relative date")

Choose a reference time appropriate to the data source and document the assumption. For incomplete dates, choose the day policy that makes sense for the application rather than accepting a library preference as if it were present in the input. The relevant settings are described in the settings reference and the dateparser overview.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

Parse repeated strings from one source

For a stream of strings from the same source, consider DateDataParser instead of repeatedly calling the default parse function. An instance caches detected languages and prioritizes those languages on subsequent parses, which can suit source-specific processing. This is a usage choice, not a documented performance guarantee. See Using DateDataParser.

from dateparser import DateDataParser

parser = DateDataParser(languages=["en"])

for text in ["March 15, 2024", "April 2, 2024"]:
    result = parser.get_date_data(text)
    print(result)

Use the normal parse function for a one-off value or simple call site; use a reusable parser when its language-caching behavior is useful for a repeated source. In either case, keep input validation and assumptions visible.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choose language detection intentionally

If the language is already known, pass it directly instead of expecting a detector to infer it from a short numeric string. A custom detect_languages_function is available for applications with their own detector. The documentation warns that detection can fail for short strings and recommends combining a detector with DEFAULT_LANGUAGES. It also describes an optional langdetect integration and says fastText support has been removed (custom language detection documentation).

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

Language detection is useful when input genuinely varies and language is not known in advance; it is not a substitute for source metadata. For a numeric-only date, language detection cannot tell you which side of the date represents the month. Supply the language and date-order policy from the source where possible.

Common parsing problems and fixes

  • The result is None. The string was not parsed successfully. Check spelling and input content, provide the known format or language, and handle failure rather than assuming a value exists.
  • A numeric date has the wrong month and day. The string is ambiguous. Set DATE_ORDER; if locale precedence overrides it, also set PREFER_LOCALE_DATE_ORDER to False.
  • The result is naive or uses an unexpected zone. Decide what zone an input without an offset represents, configure TIMEZONE or TO_TIMEZONE as appropriate, and check tzinfo and instant semantics.
  • “Tomorrow” changes on different runs. Relative parsing depends on the reference time. Supply RELATIVE_BASE for repeatable interpretation.
  • A month-and-year input gets an unexpected day. The day is missing from the source. Set PREFER_DAY_OF_MONTH to the desired documented policy.
  • A short string is assigned the wrong language. Detection can fail on short input. Pass the known language or configure an appropriate fallback such as DEFAULT_LANGUAGES.
  • Unrelated text produces a plausible date. Flexible parsing can accept unintended content. Constrain input to valid date text and validate the parsed result against application rules.

Or skip the browser setup

For a separate task—capturing a webpage as an image or PDF—ScreenshotNeo offers a one-request screenshot API. It does not parse datetime strings or replace dateparser; it is relevant when the workflow also needs webpage captures.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for request options. ScreenshotNeo accepts cookie or consent banners as a visitor and removes 60+ known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers identify the page verdict and billing status. It also provides an MCP server with screenshot, page-info, and PDF tools for AI agents. The free plan includes 1,000 shots a month with no card; paid plans start at $5 for 3,000 shots. Visit ScreenshotNeo or sign up for 1,000 free screenshots a month with no card.

Frequently Asked Questions

Which dateparser version is shown in the documentation?

The current documentation cited here displays version 1.4.3; check the official documentation for the version applicable to your environment.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Can dateparser use my application’s own language detector?

Yes. Its API supports a custom detect_languages_function; the custom detection documentation describes the integration and its limitations.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.