Python program to display various datetime formats

PythonServer Side ProgrammingProgramming

The datetime module supplies classes for manipulating dates and time. We will display different formats like day of the week, week number, day of the year, etc.


Step 1: Import datetime.
Step 2: Print day of the week.
Step 3: Print week number.
Step 4: Print day of the year.

Example Code

Live Demo

import datetime

print("Day of the week: ","%A"))
print("Week number: ","%W"))
print("Day of the year: ","%j"))


Day of the week:  Sunday
Week number:  06
Day of the year:  045


The arguments of the strftime() function are explained below:

  • %A: Weekday's full name (Example: 'Monday')
  • %W: Week number of the year with sunday as first day of the week
  • %j: Day of the year as a zero padded decimal number
Updated on 16-Mar-2021 11:09:09