Get Day Name from Date in Python

In Python, there are many situations where days and dates are involved. For example, to specify a particular time frame of a task, including dates in a data frame, etc. This tutorial will tell how day names can be found from a specific date mentioned in Python. There are various many ways to perform this.

Use the Calendar Module to Get the Name of the Day in Python

The Calendar Module is a built-in module in Python that is used for all the operations related to the calendar.

In this method, the calendar module is used because of its day_name() method. The day_name() method is used to manage an array that consists of the days of the week. In the array, Monday is marked at the 0th index value.

Example:

Output:

Monday

Explanation:

  • In the above code, we first start by importing the datetime module which is a module used in Python to work with dates and time.
  • Then we import the calendar module.
  • After that, we use the date.today() method to find out today’s date.
  • Finally, we use the day_name() method of the calendar module in which we use the date.today() method as an argument to find out the day.

Use the strftime() Method to Get the Name of the Day in Python

The strftime() method is used to return a string that represents date and time using a date, time or datetime object.

In this method, the strftime() method takes the %A which is a directive as a parameter that is used to return the name of the weekday.

Example:

Output:

Monday

Use Pandas Timestamp Method to Get the Name of the Day in Python

Pandas is one of the most common modules in python. This module helps in dealing with structured and time-series data in a more fast and efficient manner. This module is highly used in data analysis in python.

Pandas Timestamp method is very useful if the date is specified in a string format. The Timestamp() method accepts the date in YYYY-MM-DD format as the parameter.

After that, the day_name() method is used to return the name of the respective day.

Example:

Output:

0 Monday

Use the weekday() Method to Get the Name of the Day in Python

The weekday() method is a method of the datetime module. This method is used to return the day of the week. The datetime.today() method is used to return the current date while the weekday() method returns the specific day of the week in the form of an integer.

In the weekday() method, Monday is indexed as 0and Sunday is indexed as 6.

Example:

Output:

0

Use the isoweekday() Method to Get the Name of the Day in Python

The isoweekday() method is very similar to the weekday() method. The one and only difference in this method is that Monday is marked as 1 and not 0 like in the weekday() method.

Example:

Output:

1

That’s all about how to get day Name from date in Python.

Was this post helpful?


import_contacts

You may also like:

Related Posts

  • 18 May

    Get Hour from datetime in Python

    Table of ContentsHow to get hour from datetime in Python?Using the time() function and manually slicing out the hour part to get hour from datetime in Python.Using the % operator along with the datetime.hour attribute to get hour from datetime in Python.Using the format() function along with the datetime.hour attribute to get hour from datetime […]

  • 18 May

    Convert Month Name to Number in Python

    Table of ContentsHow to convert month name to number in Python?Creating a user-defined function and utilizing it to convert month name to number in Python.Using the calendar module to create a dictionary and utilize it to convert month name to number in Python.Using dict comprehension and the calendar module to convert month name to number […]

  • 18 May

    Add Hours to datetime in Python

    Table of Contentsdatetime in PythonWays to add hours to datetime in PythonUsing the datetime.Hour Attribute to Add Hours to datetime in PythonUsing the datetime.timedelta object to add hours to datetime in PythonUsing the dateutil.Relativedelta Object to Add Hours to datetime in PythonUsing the pandas.Date Offset() Function to Add Hours to datetime in PythonUsing the arrow.shift() […]

  • Format Date to YYYYMMDD in Python
    03 March

    Format Date to YYYYMMDD in Python

    Table of ContentsDate formats in PythonHow to convert date to YYYYMMDD format in PythonUsing datetime.strftime() Function to Format Date to YYYYMMDD in PythonUsing datetime.date Object to Format Date to YYYYMMDD in PythonUsing date.isoformat() Function to Format Date to YYYYMMDD in PythonUsing arrow.format() Function to Format Date to YYYYMMDD in PythonUsing pendulum.to_date_string() Function to Format Date […]

  • Get today's date in Python
    03 March

    Get Today’s Date in Python

    Table of ContentsDate and Time objects in PythonGet Today’s Date in PythonUsing date.today() Function to Get Today’s Date in PythonUsing datetime.today() and datetime.strftime() Functions to Get Today’s Date in PythonUsing datetime.now() Function to Get Today’s Date in PythonUsing strftime() Function to Get Today’s Date in PythonUsing time.strftime() Function to Get Today’s Date in PythonUsing arrow.now() […]

  • Add seconds to datetime in Python
    11 February

    Add Seconds to Datetime in Python

    Table of ContentsDate and Time in PythonWays to add seconds to datetime object in PythonUsing the datetime.timedelta object to add seconds to datetime in PythonUsing the datetime.time.second attribute to add seconds to datetime in PythonUsing the arrow.shift() function to add seconds to arrow object in PythonConclusionWas this post helpful? Date and Time in Python Python […]

Leave a Reply

Your email address will not be published.

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.