Ctrl K

Spelled-Out Date to ISO

Easy
An old mailing system stores dates the way they appear in letters: the day with its ordinal suffix, then the three-letter month abbreviation, then the year, for example "3rd Mar 1987". The parts are separated by single spaces. The day is a number from 1 to 31 followed by st, nd, rd or th (1st, 2nd, 3rd, 4th, …, 11th, …, 21st, …). The month is one of Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec. Convert text to the YYYY-MM-DD format: a four-digit year, a two-digit month and a two-digit day joined by dashes.
Example 1
text="9th Apr 2017" → '2017-04-09'

April is the fourth month, so both month and day get a leading zero: 2017-04-09.

Example 2
text="31st Dec 1999" → '1999-12-31'

The last day of 1999: 1999-12-31.

Example 3
text="22nd Feb 2100" → '2100-02-22'
Constraints
  • text has the form <day> <month> <year>
  • 1900 ≤ year ≤ 2100
  • The date exists in the calendar
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsValue of a Roman Numeral EasyShared Start of Words EasyBracket Balance EasyWhere the Fragment Starts EasyLength of the Final Word Easy
loading Python…
Input
text="9th Apr 2017"
Expected
'2017-04-09'

Run checks the first 3 tests in your browser. Submit checks all 112 tests on the server, hidden ones included.