Skip to main content
Parses various date string formats into datetime objects, returning only the date part with time set to midnight. This utility function provides robust date parsing capabilities for a wide range of common formats.

Key features

  • Returns only the date part (year, month, day)
  • Time is always set to 00:00:00
  • Supports multiple international formats
  • Handles timezones and AM/PM formats

Supported formats

The function handles these date format categories:

Standard date formats

  • DD/MM/YYYY: “22/11/2024”, “13/12/2024”
  • MM/DD/YYYY: “01/17/2025”, “10/25/2024”
  • Single-digit variants: “8/16/2019”, “9/28/2024”

Date-time combinations

  • With 24-hour time: “22/11/2024 21:19:05”
  • With AM/PM: “12/09/2024 9:00 AM”
  • With dash separator: “12/19/2024 - 2:00 PM”

Timezone support

  • With timezone abbreviations: “10/23/2024 12:06 PM CST”
  • With timezone offset: “01/17/2025 3:00:00 PM CT”

Text month formats

  • Short month: “5 Dec 2024”, “11 Sep 2024”
  • With time: “5 Dec 2024 8:00 AM PST”
  • Full month: “November 14, 2024”, “January 31, 2025, 5:00 pm”

Examples

Arguments

date_string
str
required
A string containing a date in various possible formats

Returns: datetime | None

Returns a datetime object with only date components preserved (year, month, day), time always set to 00:00:00, or None if parsing fails