runtime
201 / 500
question 201 Dates Numbers & Regex · easy

Convert US-style invoice timestamps

The original Online Retail II spreadsheet writes invoice times the American way, month first and without leading zeros: 12/1/2010 8:26. A database import needs ISO 8601 text instead.

Functioninvoice_timestamp(text)
textmonth/day/year hour:minute, e.g. 12/1/2010 8:26 is 1 December 2010 at 08:26
Returnsthe ISO text from isoformat(), e.g. '2010-12-01T08:26:00'
Errorstext that isn't a real date in this layout raises ValueError (don't catch it)
Examples
callinvoice_timestamp('12/1/2010 8:26')returns'2010-12-01T08:26:00'
callinvoice_timestamp('1/18/2011 10:01')returns'2011-01-18T10:01:00'
callinvoice_timestamp('12/9/2011 12:50')returns'2011-12-09T12:50:00'

Loading your progress…

Convert US-style invoice timestamps — Python practice · Runtime