IniziaInizia gratis

Working with the datetime library

We will be exploring the datetime library, specifically the datetime.strptime(date_string, format) method that converts a string date in a specific string format by identifying day, month and year. Using the table provided, determine the appropriate code to identify the year, month, and day from the dates below (you can check your answers by printing the method in the console):

  • 12-01-1990 (US Format m-d-y)
  • 23/08/2020 (EU Format d-m-y)
Directive Meaning Example
%d Day of the month as a zero-padded decimal number 01, 02, …, 31
%b Month as locale’s abbreviated name Jan, Feb, …, Dec
%B Month as locale’s full name January, …, December
%m Month as a zero-padded decimal number 01, 02, …, 12
%y Year without century as a zero-padded decimal number 00, 01, …, 99
%Y Year with century as a decimal number 1970, 1988, 2001, 2013

Questo esercizio fa parte del corso

Financial Forecasting in Python

Visualizza il corso

Esercizio pratico interattivo

Passa dalla teoria alla pratica con uno dei nostri esercizi interattivi

Inizia esercizio