SQL PHP HTML ASP JavaScript articles and free scripts to download If you are facing any problem in viewing this page, please tell us
 
 

Displaying Date with format


We can display the present day of the week by using getDay function of the JavaScript date object. Here getDay function will return 0 to 6 based on the day. Number 6 will be returned for Sunday and 1 for Monday.

We will create one day array with all the names of the seven days will be stored. Based on the value returned by getDay function the name of the day will be displayed from the array.

Here is the demo of the getDay function.





Here is the full code of the above demo.

<html>
<head>
<title>(Type a title for your page here)</title>
<script type="text/javascript">
function show_now(){
var my_day=new Date()
//var dt = new Date(\"Aug 16, 2005 05:55:00\");

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"

alert ("Today Day is = " + day_name[my_day.getDay()]);
}
</script></head>


<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">

<input type=button value="Show Day" onclick="show_now();">

</body>
</html>

Further readings
Countdown script displaying days , hours , minutes and seconds left from an event
Displaying changing Clock showing date and time in a web page
Timer function to set time for reminder alert
Timer Resetting the timer function
Recursive timer to trigger a code block after a particular interval
Displaying current date and time alert
Displaying Current Month using getMonth() function
Displaying present Year using getFullYear()
Showing Current Date using getDate() function
Displaying Current Day using getDay() function
Sections
PHP
JavaScript
ASP
HTML
SQL
Photoshop
Articles SEO
Date & Time
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.