Python datetime isoweekday() Method with Example

Python datetime.isoweekday() Method: In this tutorial, we will learn about the isoweekday() method of datetime class in Python with its usage, syntax, and examples. By Hritika Rajput Last updated : April 22, 2023

Python datetime.isoweekday() Method

The datetime.isoweekday() method is used get the day of the week as an integer, where Monday is 1 and Sunday is 7. It is the same as datetime.weekday() function where we consider Monday is 0 incrementing by one for the coming days. It is an instance method as it works on an instance of the date class.

Module

The following module is required to use isoweekday() method:

import datetime

Class

The following class is required to use isoweekday() method:

from datetime import datetime

Syntax

The following is the syntax of isoweekday() method:

isoweekday()

Parameter(s)

The following are the parameter(s):

  • None

Return Value

The return type of this method is a number which tells us what is the day of the week on that day.

Example of datetime isoweekday() Method in Python

## importing datetime class
from datetime import datetime

## Since we know the number, 
## we can save them in a list and 
## print the day on that number
day =["0","Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]

## Creating an instance
x = datetime.today() ## or use datetime.now()
d = x.isoweekday()
print("Today's isoweekday number is:", d)
print("Today's day is:",day[d])

x = datetime(2010, 1, 1)
print("Day on", x.year,"new year was:", day[x.isoweekday()])

x = datetime(2011, 1, 1)
print("Day on", x.year,"new year will be:", day[x.isoweekday()])

Output

Today's isoweekday number is: 5
Today's day is: Friday
Day on 2010 new year was: Friday
Day on 2011 new year will be: Saturday



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.