Day of the week from entered date

We can get day of the week ( Sunday, Monday etc ) from the entered date by using getDay function. So by entering any date in mm/dd/yy format we can get the week day of it.

First we will read the entered date and then by using split command we will collect the date, month and year from it. Then by using them we will create a date object. This date object then we will use to get the week days by using getDay function. The output of getDay will be in the form of number starting from 0 and ending with 6 based on the week day. To display the full day we will use one array and display the week days accordingly.

Here is the Demo of week day

Here is the script.

<title>demo of getting day of the week from eneterd date</title>
<script type="text/javascript">
function disp_day(){
var str=document.getElementById('dt').value;
var a1=str.split("/");
var dt= new Date();
dt.setMonth(a1[0]-1);// Month part
dt.setDate(a1[1]); // Date part
dt.setFullYear(a1[2]); // Year part
//display the full date //

var disp =dt.getDay(); // get the day of the week 0 to 6
var day_name=new Array(7);



<div id="txtHint1"></div>

<div id="txtHint"></div>
<input type=text name=dt id=dt><input type=button value='Display Day' onClick=disp_day()><br>


Subscribe to our YouTube Channel here


* indicates required
Subscribe to plus2net

    Post your comments , suggestion , error , requirements etc here .

    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 All rights reserved worldwide Privacy Policy Disclaimer