Parse an ISO Date String

Easy ⏱ 8 min 81% acceptance ★★★★★ 4.7
Write parse_date(text) converting a 'YYYY-MM-DD' string into a datetime.date object using datetime.strptime (then .date()), raising the natural ValueError for malformed input — don't catch it.

Examples

Example 1
Input
parse_date('2026-07-28')
Output
date(2026, 7, 28)
Explanation

The format codes %Y-%m-%d match the layout.

Constraints

  • Use strptime, not string slicing.
  • Return a date, not a datetime.

Topics

Date & Timestrptime

Companies

TCSInfosysSalesforce

Hints

Hint 1

datetime.strptime(text, '%Y-%m-%d').

Hint 2

.date() strips the time part.

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