Connecting Tech Pros Worldwide Forums | Help | Site Map

Help with date functions

Newbie
 
Join Date: Feb 2008
Posts: 4
#1: Feb 18 '08
I would appreciate very much if someone could help me figure out what I am doing wrong. I have checked the code over and over and still can't figure out why it won't write to the web page. Perhaps an outside eye could help. Here goes...not sure which tags to use for .js so forgive me if I just cut/paste.

Here's my js file:
Expand|Select|Wrap|Line Numbers
  1. function XmasDays(thisDate) {
  2.    var XMYear=thisDate.getFullYear();
  3.    var XMDay=new Date("December, 25, 2005");
  4.    XMDay.setFullYear(XMYear);
  5.    var dayTotal=(XMDay-thisDate)/(1000*60*60*24);
  6.    dayTotal=Math.round(dayTotal);
  7.    return dayTotal;
  8.  
  9. function showDate(thisDate){
  10.     var thisWDay=thisDate.getDay();
  11.     var thisDay=thisDate.getDate();
  12.     var thisMonth=thisDate.getMonth();
  13.     var thisYear=thisDate.getFullYear();
  14.     var monthName=new Array(12);
  15.     monthName[0]="January";
  16.     monthName[1]="February";
  17.     monthName[2]="March";
  18.     monthName[3]="April";
  19.     monthName[4]="May";
  20.     monthName[5]="June";
  21.     monthName[6]="July";
  22.     monthName[7]="August";
  23.     monthName[8]="September";
  24.     monthName[9]="October";
  25.     monthName[10]="November";
  26.     monthName[11]="December";
  27.     var wdayName=new Array(7);
  28.     wdayName[0]="Sunday";
  29.     wdayName[1]="Monday";
  30.     wdayName[2]="Tuesday";
  31.     wdayName[3]="Wednesday";
  32.     wdayName[4]="Thursday";
  33.     wdayName[5]="Friday";
  34.     wdayName[6]="Saturday";
  35.  
  36.     dateString="weekday, month day, year";
  37.     return (wdayName[thisWDay]+","monthName[thisMonth]+","+thisYear);
  38. }
  39.  
  40.  
  41. Here's the embedded scripts:
  42. <td id="daycell">
  43. <script type="text/javascript">
  44.     <!--Hide from non-JavaScript Browsers
  45.  
  46.     var today = new Date("Mon, Dec 24, 2008");
  47.     var niceDate = showDate(today);
  48.     var daysLeft = XmasDays(today);
  49.     document.write(niceDate+"< /br>");
  50.  
  51.         if (daysLeft > 1) { 
  52.         document.write("Only "+ daysLeft+"days until Christmas");
  53.         }else if( daysLeft==1){
  54.         document.write("Last day for Christmas Shopping")
  55.         }else{
  56.         document.write("Happy Holidays from North Pole Novelties");        
  57.         }
  58.  
  59. //Stop hiding-->
  60. </script>
here's my link:
[HTML]<title>North Pole Novelties</title>
<link href="styles2.css" rel="stylesheet" type="text/css" />
<script src="library2.js" type="text/javascript"></script>
</head>[/HTML]
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#2: Feb 18 '08

re: Help with date functions


Is the embedded script in the body?
Newbie
 
Join Date: Feb 2008
Posts: 4
#3: Feb 20 '08

re: Help with date functions


Yes, it's in my first cell.
Newbie
 
Join Date: Feb 2008
Posts: 4
#4: Feb 21 '08

re: Help with date functions


Any help is appreciated. Thanks
Familiar Sight
 
Join Date: Oct 2006
Posts: 141
#5: Feb 21 '08

re: Help with date functions


Hi ,

ur code is perfectly right but the wrong is in the showDate(thisdate) function

the wrong is simple syntax error ie

return (wdayName[thisWDay]+"," + monthName[thisMonth]+","+thisYear);

Place the bold one its enough


Quote:

Originally Posted by nooby101

I would appreciate very much if someone could help me figure out what I am doing wrong. I have checked the code over and over and still can't figure out why it won't write to the web page. Perhaps an outside eye could help. Here goes...not sure which tags to use for .js so forgive me if I just cut/paste.

Familiar Sight
 
Join Date: Oct 2006
Posts: 141
#6: Feb 21 '08

re: Help with date functions


Hi ,

ur code is perfectly right but the wrong is in the showDate(thisdate) function

the wrong is simple syntax error ie

return (wdayName[thisWDay]+"," + monthName[thisMonth]+","+thisYear);

Place the bold one its enough



Quote:

Originally Posted by nooby101

Any help is appreciated. Thanks

Newbie
 
Join Date: Feb 2008
Posts: 4
#7: Feb 23 '08

re: Help with date functions


OMG!!!! Thank you soooo much! You have no idea how much this has been driving me crazy! I figured it was something very simple. Amazingly my instructor couldn't pick that up either :) You are the man!.....or woman!
Reply