close

How to get the Day of the Week in Python

In this tutorial we will learn about of How to get the Day of the Week in Python. By using different methods you can get the index of the current day or by some methods you can get the direct name of the current day. Here are i give you some methods. I hope you guys like it. So without wasting your time. Lets learn about of this.

How to get the Day of the Week in Python

Here are some methods to get the current day of the week in python. Lets see this by these methods.

  1. Use weekday()
  2. Use isoweekday()
  3. Use calendar
  1. Get the Day of the Week in Python

    to get the Day of the Week in Python just Use weekday(). By using weekday() you can get the current day in the basis of monday is indexed by 0 and sunday is by 6. we use here datetime.today() with weekday which will give us the index of today. So lets learn this by given below example: from datetime import datetime print(datetime.today().weekday()) Output : 1

  2. How to get the Day of the Week in Python

    to get the Day of the Week in Python just Use isoweekday().This a little different from weekday. Here is the monday is indexed by 1 instead of 0 and sunday is by 7 instead of 6. Here i used isoweekday() with datetime.today and it give us the index of the current day. Lets see this by example: from datetime import datetime print(datetime.today().isoweekday()) Output : 2

Method 1: Use weekday()

By using weekday() you can get the current day in the basis of monday is indexed by 0 and sunday is by 6. we use here datetime.today() with weekday which will give us the index of today. So lets learn this by given below example:

from datetime import datetime
print(datetime.today().weekday())

Output :

1

Method 2: Use isoweekday()

This a little different from weekday. Here is the monday is indexed by 1 instead of 0 and sunday is by 7 instead of 6. Here i used isoweekday() with datetime.today and it give us the index of the current day. Lets see this by example:

from datetime import datetime
print(datetime.today().isoweekday())

Output :

2

Method 3: Use calendar

By importing calendar you can get the name of the current day in python. Thus by this you can get the name. Here we use day_name to get the name of the current day. Lets see how this method work by an example:

from datetime import date
import calendar
currentdate = date.today()
print(calendar.day_name[currentdate.weekday()])

Output :

Tuesday

Method 4: Use timestamp()

timestamp gives us the current day of the week and the index of it. For use this we have to put the date of the day we want to know. So lets see this by example:

import pandas as pd
temp = pd.Timestamp('2022-02-22')
print(temp.dayofweek, temp.day_name())

Output :

1 Tuesday

Conlusion

Hope all 6 Method Are Useful For You. Comment Below Which Method You Used To Convert String To Datetime In Python. Thank You.

Also Read

Leave a Comment