473,386 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 1532
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,658 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

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

Similar topics

4
by: Funnyweb | last post by:
I have just notices that the date() function is not returning the correct date/time on my "server". I am running apache2 on my winxp pro laptop. My system clock is set to the correct date,...
3
by: Sharad Gupta | last post by:
Friends I need a date simple date function that would append the coming month value in my current month like monthname(month(date)) : gives me current month in string i need next month , a...
2
by: ltamisin | last post by:
Hi Im working on a Year(Date) function right now, the output of that function is this "2005", my question is how can i change the format into this "05" Function: Year(Date) Output: 2005...
8
by: Dennis M. Marks | last post by:
What is the maximum valid date range for the date(yyyy,mm,dd) function. -- Dennis M. Marks http://www.dcs-chico.com/~denmarks/ Replace domain.invalid with dcsi.net -----= Posted via...
5
by: Dennis M. Marks | last post by:
After reading section 15.9.1.1 the ECMAScript Language Specifications I see that the date range for the Date function is +/- 100,000,000 days from 01 Jan 1970. This is called an extrapolated...
6
by: bryan.seaton | last post by:
I have a delete statement that is not doing what I want it to do: Delete from LOG_TABLE where (DATE(LOG_TS)) < (DATE(CURRENT_DATE)- 21 DAYS); It is supposed to delete all records that are 21...
4
by: Christine | last post by:
I am having the strangest problem. I use the Date function in several of my forms and modules in an Access 2000 mdb. Lately, wherever in my code (in this one mdb) I use the Date function, it...
5
by: Ian Davies | last post by:
Dear Access expert I am trying to use an mde application developed in Access2k with Access 2002. I get an Access error box: Function is not available.. Date() etc. Is Access 2002 back...
4
by: Patrick McGuire | last post by:
I need to get the current date in vb .NET. In vba I always used the Date() function, and the help in .NET indicates that this function still exists, but I can't seem to find it. The Now()...
3
by: murch.alexander | last post by:
I made a simple public function to set and return a date value (see below). I have a number of queries that call up the function to get the "As Of Date," which is typically set to today's date....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.