Parse Dates in Mixed Formats

Hard ⏱ 18 min 27% acceptance ★★★★★ 4.5
Legacy exports mix '2026-07-28', '28/07/2026' and 'Jul 28, 2026'. Write parse_any(text) trying each format in that order with strptime, returning the date on first success or None when none fit — the try/except-per-format pattern.

Examples

Example 1
Input
parse_any('28/07/2026')
Output
date(2026, 7, 28)
Explanation

The second format matched.

Constraints

  • Exactly those three formats.
  • Return None on total failure.

Topics

Date & Timemulti-format parsing

Companies

DeloitteEYCapgemini

Hints

Hint 1

Formats: '%Y-%m-%d', '%d/%m/%Y', '%b %d, %Y'.

Hint 2

Loop over the formats; return inside the try.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.