Day and Date Display with HTML

Hi Sam,

I've been with you for more than two years and have only positive things to say about you and your programming abilities.

That being said can you generate the HTML code that I can place on my site that will automatically display the correct day and date.

I would like my home page to great a visitor with "Welcome to Circle W Leather - Today is (DAY, DATE).

Or to where I would be able to display the number of days to a specific date "You have (days) to the New Year.

I think many of your users would find a script like that very useful.

Thanks - Frank

RE: Day and Date Display with HTML

Below are some Date and Time JavaScripts you can add to your site.

You should add the scripts to the <head> section of your site pages. Use the Additional Code function to add the code to your site. See the following page for more information: Adding Your Own HTML or Scripting Code.

Note: You should first remove all the line breaks to make a single line of contiguous code before you add it into the XLEcom program. If you are going to copy and paste the single line of contiguous code below, make sure when you paste it into a document that the quotes are transferred as real quotes. For testing purposes, it is best to paste the code into a blank ASCII text document, save it as an HTML file, and open it in your web browser.

Date Script
The following script displays the Date as: April 12, 2008

<script type="text/javascript">
<!--
function makeArray(n) {
this.length = n;
return this;
}
monthNames = new makeArray(12);
monthNames[1] = "January";
monthNames[2] = "February";
monthNames[3] = "March";
monthNames[4] = "April";
monthNames[5] = "May";
monthNames[6] = "June";
monthNames[7] = "July";
monthNames[8] = "August";
monthNames[9] = "September";
monthNames[10] = "October";
monthNames[11] = "November";
monthNames[12] = "December";
function dateString(oneDate) {
var theMonth = monthNames[oneDate.getMonth() + 1];
var theYear = oneDate.getFullYear();
return theMonth + " " + oneDate.getDate() + ", " + theYear;
}
//-->
</script>
<font face="Verdana, Arial, Helvetica, sans-serif" color=#0000ff size=2><b><script type="text/javascript">document.write(dateString(new Date()))</script></b></font>

Same code as a single line of contiguous code - No line breaks
<script type="text/javascript">function makeArray(n) {this.length = n;return this;} monthNames = new makeArray(12); monthNames[1] = "January"; monthNames[2] = "February"; monthNames[3] = "March"; monthNames[4] = "April"; monthNames[5] = "May"; monthNames[6] = "June"; monthNames[7] = "July"; monthNames[8] = "August"; monthNames[9] = "September"; monthNames[10] = "October"; monthNames[11] = "November"; monthNames[12] = "December"; function dateString(oneDate) {var theMonth = monthNames[oneDate.getMonth() + 1];var theYear = oneDate.getFullYear();return theMonth + " " + oneDate.getDate() + ", " + theYear;}</script><font face="Verdana, Arial, Helvetica, sans-serif" color=#0000ff size=2><b><script type="text/javascript">document.write(dateString(new Date()))</script></b></font>


Day and Date Script
The following script displays the Date as: Last update: Saturday, April 12th, 2008

Note: You can remove the "Last update:" statement by removing the Last update: text from the the code below.

<script type="text/javascript">
<!--
d = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
m = new Array("January","February","March","April","May","June","July","August","September","October","November","December");

today = new Date();
day = today.getDate();
year = today.getYear();

if (year < 2000)
year = year + 1900;

end = "th";
if (day==1 || day==21 || day==31) end="st";
if (day==2 || day==22) end="nd";
if (day==3 || day==23) end="rd";
day+=end;

document.write("<center>Last update: ");
document.write(d[today.getDay()]+", "+m[today.getMonth()]+" ");
document.write(day+", " + year);
document.write("</center>");
//-->
</script>

Same code as a single line of contiguous code - No line breaks
<script type="text/javascript">d = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"); m = new Array("January","February","March","April","May","June","July","August","September","October","November","December");today = new Date();day = today.getDate();year = today.getYear();if (year < 2000) year = year + 1900;end = "th";if (day==1 || day==21 || day==31) end="st";if (day==2 || day==22) end="nd";if (day==3 || day==23) end="rd";day+=end;document.write("<center>Last update: ");document.write(d[today.getDay()]+", "+m[today.getMonth()]+" ");document.write(day+", " + year);document.write("</center>");</script>


Date Countdown Script
Note: To see this script work properly, change today.getMonth() == 10 to today.getMonth() == 7 for August, if August is the current month.

<script type="text/javascript">
<!--
var today = new Date();
if (today.getMonth() == 10) {
       var days_left = 23 - today.getDate();
       if (days_left > 0) {
               document.write("<b>Count Down: <font color=ff3333>" + days_left + "</font> Days until Thanksgiving</b>");
       }
}
// -->
</script>

Same code as a single line of contiguous code - No line breaks
<script type="text/javascript">var today = new Date();if (today.getMonth() == 10) {var days_left = 23 - today.getDate();if (days_left > 0) {document.write("<b>Count Down: <font color=ff3333>" + days_left + "</font> Days until Thanksgiving</b>");}}</script>

I hope this helps you.

Sam Raheb
XLEcom Program Developer