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.


mm/dd/yy



Here is the script.
<html>
<head>
<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 //
document.getElementById("txtHint1").innerHTML=dt;

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

day_name[0]="Sunday"; 
day_name[1]="Monday"; 
day_name[2]="Tuesday"; 
day_name[3]="Wednesday"; 
day_name[4]="Thursday"; 
day_name[5]="Friday"; 
day_name[6]="Saturday"; 

document.getElementById("txtHint").innerHTML=day_name[disp];
}
</script>
</head>

<body>
<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>
mm/dd/yy 

<br>
</body>
</html>

Date Reference All Date Projects
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com










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