Webmaster Key - Discussion Forums


Welcome, Guest. Please login or register.
Did you miss your activation email?
February 09, 2012, 02:49:17 PM

Login with username, password and session length
Welceome to Forums!

Important information for guests and new members:

In order to understand the full benefits of becoming an active member of this forum, please review the following information on guest and new member restrictions. These forum changes have been prompted by an overwhelming and unreasonable amount of bot postings and incoherent guest spam messages. We wish to prevent these events from happening in the future and make our community a more comfortable place for all of our members.

For guests:

Guests are not allowed to open new topics, polls, or posts attachments.
If you wish to open up new discussions on this forum, we encourage you to register.

For new members:

New members with less than five posts are not allowed to modify additional profile information such as avatars, contact information, biographies, and signatures. However, new members are encouraged to post their own topics or reply to topics initiated by other members. Become active on the forums and 5 posts should be an easy task!

We are a diverse community with members from all over the world. We encourage new ideas and interesting conversation. Do not be afraid to post webmaster/computer-related questions or problems, as our active members are always willing to help when they are able. Interested? Join us.

+ Webmaster Key Forums
|-+ Webmaster Corner
| |-+ Site Design and Web Authoring
| | |-+ JavaScript - Calculate Date?
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] Go Down Stumble Upon! Digg It! del.icio.us! Add to Technorati! ReddIt!  Send this topic Print
Author Topic: JavaScript - Calculate Date?  (Read 2272 times)
websj06
Jr. Member
*
Posts: 31


« on: November 25, 2006, 06:27:35 PM »


hello everyone:

I have an question regarding calculation involve dates.

the problem is like this. Show final examdate is December 20, 2006. Check the current date against
the final date.
a) if it is not the final exam date yet show how many days left before final
b) if it is final exam date, print a message to say it is final day.

 
 my approach is initialize final date in string format, then convert current date to string format.
 do calculation to see if final date has been reached.
 
 
Code:
/*variable initialization for current date */
  var curDate = new Date();
  var curDay = curDate.getDay();
  var monthDay = curDate.getDate();
  var curMonth = curDate.getMonth() + 1;
  var curYear = curDate.getFullYear();
 
 /* variable initialization for last day of class */
  var finalDay = new Date ("December 20, 2006");
  var lastDay = finalDay.getDate();
  var lastMonth = finalDay.getMonth() + 1;
  var lastYear = finalDay.getFullYear();

  var month = new Array ("", "Jan", "Feb","Mar","Apr","May","Jun", "Jul", "Aug",
                            "Sep","Oct","November","December");
  var temp = (month[curMonth] + " "+ monthDay +", " + curYear);
 
 
  //convert current date to string format
  var temp = (month[curMonth] + " "+ monthDay +", " + curYear);
 
  //calculation that converts time to days
  var temp1 = (finalDay - temp) / (1000 * 60 * 60 * 24);
 
  alert (temp1);
 
  the output is NaN. I think probably value of temp variable doesn't math with finalDay variable.
  How can I fix this problem, so I can display days as a whole number.
 
  Please give me some suggestions. thanks!
Report to moderator   Logged
Pages: [1] Go Up Stumble Upon! Digg It! del.icio.us! Add to Technorati! ReddIt!  Send this topic Print 
+ Webmaster Key Forums
|-+ Webmaster Corner
| |-+ Site Design and Web Authoring
| | |-+ JavaScript - Calculate Date?

Jump to:  
« previous next »


Our Partners
RelmaxTOP Ranking System Web Hosting RelmaxTOP Ranking System
Staff Sites
12Noon[12Noon Gallery] Andy[Urgentclick]
Tamuril[Tamuril's Digital Art Exhibit] Sensovision
Powered by MySQL Powered by PHP We are hosted by Relmax Inc. |Our Privacy Policy | Sitemap
Powered by SMF 1.1.9 | SMF © 2006-2009, Simple Machines LLC
Forum design by Tamuril © 2005.
Valid XHTML 1.0! Valid CSS!