469,276 Members | 1,898 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,276 developers. It's quick & easy.

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:

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.  
  10. function showDate(thisDate) {
  11.    var thisWDay=thisDate.getDay()
  12.    var thisDay=thisDate.getDate();
  13.    var thisMonth=thisDate.getMonth();
  14.    var thisYear=thisDate.getFullYear();
  15.    var monthName = new Array(12);
  16.    monthName[0]="January";
  17.    monthName[1]="February";
  18.    monthName[2]="March";
  19.    monthName[3]="April";
  20.    monthName[4]="May";
  21.    monthName[5]="June";
  22.    monthName[6]="July";
  23.    monthName[7]="August";
  24.    monthName[8]="September";
  25.    monthName[9]="October";
  26.    monthName[10]="November";
  27.    monthName[11]="December";
  28.    var wdayName = new Array(7);
  29.    wdayName[0]="Sunday";
  30.    wdayName[1]="Monday";
  31.    wdayName[2]="Tuesday";
  32.    wdayName[3]="Wednesday";
  33.    wdayName[4]="Thursday";
  34.    wdayName[5]="Friday";
  35.    wdayName[6]="Saturday";
  36.    dateString="weekday, month day, year";
  37.    return (wdayName[thisWDay]+"," + monthName[thisMonth]+","+thisYear); 
  38.  
  39. }

The embedded scripts:

Expand|Select|Wrap|Line Numbers
  1. <td id="daycell">
  2. <script type="text/javascript">
  3.    <--! Hide from non-JavaScript browsers
  4.    var Today = new Date("Wed, March 3, 2011");
  5.    var niceDate = showDate(Today);
  6.    var daysLeft = XmasDays(Today);
  7.  
  8.    document.write(niceDate+"<br />");
  9.    if (daysLeft > 1) {
  10.        document.write("Only "+daysLeft+" days until Christmas");
  11.    }else {
  12. if (daysLeft==1) {
  13.     document.write("Last day for Christmas shopping");
  14.    }else {
  15.   document.write("Happy Holidays from North Pole Novelties");
  16.   }
  17.  
  18.   }
  19.  
  20.    // Stop hiding -->
  21. </script>

Sorry if it's out of whack while displayed. I copied and pasted.
Mar 3 '11 #1
3 1348
dgreenhouse
250 Expert 100+
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.
Mar 3 '11 #2
Here's an example of what I'm trying to achieve:

http://www.blacktiewebdesign.com/t10/review/npn2.html

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.
Mar 3 '11 #3
Dormilich
8,651 Expert Mod 8TB
I donít see whatís wrong with the output. 296 days from March 3rd to Christmas Eve seem sensible.
Mar 3 '11 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Sharad Gupta | last post: by
2 posts views Thread by ltamisin | last post: by
8 posts views Thread by Dennis M. Marks | last post: by
5 posts views Thread by Dennis M. Marks | last post: by
4 posts views Thread by Christine | last post: by
5 posts views Thread by Ian Davies | last post: by
4 posts views Thread by Patrick McGuire | last post: by
3 posts views Thread by murch.alexander | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.