Get the day name of date using JavaScript

Today, we’ll explain to you how to get day name of a date using JavaScript.

Sometimes we need to display the name of the day according to the given date. For example, we can display the estimated shipping day when the order is placed.

Using the JavaScript date object along with two methods date.toLocaleString() and date.getDay(), we can easily get the day of the week.

You may also like the following articles.

Methods to get day name of date

  1. toLocaleString() method
  2. getDay() method

Let’s start with an example.

1. toLocaleString() method

JavaScript date object’s toLocaleString() provides various properties with which you can extract information related to a date in any format.

You can also get the short day format using short in the second argument as shown below.

2. getDay() method

The getDay() method returns an integer representing the day of the week. (0 for sunday up to 6 for saturday)

Here, using the getDay() method, we can get the zero-based number value of the current weekday.

To get the name of day, we need to create an array of day strings which corresponds to the numeric value of the weekdayNum. Let’s check with an example.

That’s it for today.
Thank you for reading. Happy Coding..!! 🙂

If you found value in this article,
you can support us by buying me a coffee! ☕

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *