1. Learn
  2. /
  3. Courses
  4. /
  5. Working with Dates and Times in Python

Connected

Exercise

Representing dates in different ways

date objects in Python have a great number of ways they can be printed out as strings. In some cases, you want to know the date in a clear, language-agnostic format. In other cases, you want something which can fit into a paragraph and flow naturally.

Let's try printing out the same date, August 26, 1992 (the day that Hurricane Andrew made landfall in Florida), in a number of different ways, to practice using the .strftime() method.

A date object called andrew has already been created.

Instructions 1/3

undefined XP
  • 1

    Print andrew in the format 'YYYY-MM'.

  • 2

    Print andrew in the format 'MONTH (YYYY)', using %B for the month's full name, which in this case will be August.

  • 3

    Print andrew in the format 'YYYY-DDD' (where DDD is the day of the year) using %j.