I'm confused about this date function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Chris Bauer
    New Member
    • Mar 2011
    • 2

    #1

    I'm confused about this date function

    I've been wracking my brain for a couple of days trying to figure this function out. I'd like to know if I'm missing something, or if it's incorrect as a whole because I still haven't found any success in making this work. Here it is:

    Code:
    function XmasDays(thisDate) {
       var XMYear=thisDate.getFullYear();
       var XMDay=new Date("December, 25, 2005");
       XMDay.setFullYear(XMYear);
       var dayTotal=(XMDay-thisDate)/(1000*60*60*24);
       dayTotal=Math.round(dayTotal);
       return dayTotal;
    } 
    
    
    function showDate(thisDate) {
       var thisWDay=thisDate.getDay()
       var thisDay=thisDate.getDate();
       var thisMonth=thisDate.getMonth();
       var thisYear=thisDate.getFullYear();
       var monthName = new Array(12);
       monthName[0]="January";
       monthName[1]="February";
       monthName[2]="March";
       monthName[3]="April";
       monthName[4]="May";
       monthName[5]="June";
       monthName[6]="July";
       monthName[7]="August";
       monthName[8]="September";
       monthName[9]="October";
       monthName[10]="November";
       monthName[11]="December";
       var wdayName = new Array(7);
       wdayName[0]="Sunday";
       wdayName[1]="Monday";
       wdayName[2]="Tuesday";
       wdayName[3]="Wednesday";
       wdayName[4]="Thursday";
       wdayName[5]="Friday";
       wdayName[6]="Saturday";
       dateString="weekday, month day, year";
       return (wdayName[thisWDay]+"," + monthName[thisMonth]+","+thisYear); 
    
    }

    The embedded scripts:

    Code:
    <td id="daycell">
    <script type="text/javascript">
       <--! Hide from non-JavaScript browsers
       var Today = new Date("Wed, March 3, 2011");
       var niceDate = showDate(Today);
       var daysLeft = XmasDays(Today);
    
       document.write(niceDate+"<br />");
       if (daysLeft > 1) {
           document.write("Only "+daysLeft+" days until Christmas");
       }else {
    if (daysLeft==1) {
        document.write("Last day for Christmas shopping");
       }else {
      document.write("Happy Holidays from North Pole Novelties");
      }
    
      }
        
       // Stop hiding -->
    </script>

    Sorry if it's out of whack while displayed. I copied and pasted.
    Last edited by Dormilich; Mar 3 '11, 12:25 AM.
  • dgreenhouse
    Recognized Expert Contributor
    • May 2008
    • 250

    #2
    I guess I could read the code, but it would be helpful if you described what the code is supposed to accomplish.

    That way, others would have a better idea of how to help you.

    Comment

    • Chris Bauer
      New Member
      • Mar 2011
      • 2

      #3
      Here's an example of what I'm trying to achieve:



      To be more specific, notice that the red box contains the current date, and under it is the countdown to Christmas day. I've scanned my code over and over again, but I can't make sense of what I'm doing wrong or what I'm missing.

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        I don’t see what’s wrong with the output. 296 days from March 3rd to Christmas Eve seem sensible.

        Comment

        Working...