Logo 
Search:

Javascript Articles

Submit Article
Home » Articles » Javascript » Date FunctionsRSS Feeds

How to find day of the week

Posted By: Easy Tutor     Category: Javascript     Views: 7779

This article will explains you how to find day of the week in javascript.

Example: If day is

Sunday - returns 0
Monday - returns 1
Tuesday - returns 2
Wednesday - returns 3
Thursday - returns 4
Friday - returns 5
Saturday - returns 6

Syntax for How to find day of the week in Javascript

How to find day of week.

Example: If day is 
Sunday - returns 0
Monday - returns 1
Tuesday - returns 2
Wednesday - returns 3
Thursday - returns 4
Friday - returns 5
Saturday - returns 6

//Example 1//Finds Current date in javascriptvar currDate = new Date();

//Find the day of month
alert(currDate.getDay());

//Output: returns day based on current date.//Example 2var myDate = new Date("January 22, 2005 10:10:00");

//Find the day of week
alert(myDate.getDay());

//Output
6   (As January 22, 2005 was saturday)



//Method to Find day of Monthfunction TestDateFunction() {
        <!--
        //Example 1//Finds Current date in javascriptvar currDate = new Date();

        //Find the day of week
        alert(currDate.getDay());
        
        //Example 2var myDate = new Date("January 22, 2005 10:10:00");

        //Find the day of week
        alert(myDate.getDay());
        // -->
    }    

Example for How to find day of the week in Javascript

Find day of week

  
Share: 


Didn't find what you were looking for? Find more on How to find day of the week Or get search suggestion and latest updates.

Easy Tutor
Easy Tutor author of How to find day of the week is from United States. Easy Tutor says

Hello Friends,

I am Free Lance Tutor, who helped student in completing their homework.

I have 4 Years of hands on experience on helping student in completing their homework. I also guide them in doing their final year projects.

I have share many programs on this website for everyone to use freely, if you need further assistance, than please contact me on easytutor.2ya [at the rate] gmail [dot] com

I have special discount scheme for providing tutor services. I am providing tutor service to students from various contries, currently most of my students are from United States, India, Australia, Pakistan, Germany, UK and Canada.

I am also here to expand my technical network to receive more opportunity in my career, make friends to help them in resolving their technical problem, learn and share my knowledge, If you like to be my friend, Please send me friend request.

Thanks,
Happy Programming :)

 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
Todd Katz from United States Comment on: Dec 31
Having pieced this together from other Internet examples, I thought I'd share a rendition of getting dates for a particular period such as "the next five days".

Cheers,
Todd


<SCRIPT LANGUAGE="JavaScript1.2">
<!-- gets first day of period -->
var today = new Date();
var targetDay = new Date(today.getTime() + 0 * 24 * 60 * 60 * 1000);
var targetDayNum = today.valueOf() + 1000 * 60 * 60 * 24 * 0;
var d2 = (new Date(targetDayNum));
var dayNum = d2.getDay();
var dayName = ["Sun.","Mon.","Tues.","Wed.","Thurs.","Fri.","Sat."][dayNum];
var monthNum = d2.getMonth();
var monthName = ["Jan.","Feb.","March","April","May","June","July", "Aug.", "Sept.", "Oct.", "Nov.", "Dec."][monthNum];
var beginDay = dayName + ", " + monthName + " " + d2.getDate();
<!-- -->
<!-- gets last day of period -->
<!-- -->
var today = new Date();
var targetDay = new Date(today.getTime() + 6 * 24 * 60 * 60 * 1000);
var targetDayNum = today.valueOf() + 1000 * 60 * 60 * 24 * 6;
var d2 = (new Date(targetDayNum));
var dayNum = d2.getDay();
var dayName = ["Sun.","Mon.","Tues.","Wed.","Thurs.","Fri.","Sat."][dayNum];
var monthNum = d2.getMonth();
var monthName = ["Jan.","Feb.","March","April","May","June","July", "Aug.", "Sept.", "Oct.", "Nov.", "Dec."][monthNum];
var endDay = dayName + ", " + monthName + " " + d2.getDate();
document.write(beginDay + " - " + endDay);
</SCRIPT>
<!-- notes:
* To identify the begin and end period dates you only need to change the number of days in the targetDay and targetDayNum contructors. In this case "0" (today) and "6" (six days from today) were used.
* Add: ... + ", " + d2.getFullYear() in the beginDay or endDay constructor if you want the date to appear with the year as in:
Thurs., Jan. 6, 2011 - Wed., Jan. 12, 2011
-->

View All Comments