Client Side Things
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesClient Side Things

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
Dell PowerEdge Servers
  #1  
Old January 24th, 2003, 12:37 AM
StrawBerry StrawBerry is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 11 StrawBerry User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Calculating difference between two dates in javascript

Hi there,

I'm having some problems with calculating the difference between two dates.

This following function can work on two dates within the same month but it doesn't work on two dates on different months:-

firstDate = new Date(year1, month1, day1);
secondDate = new Date(year2, month2, day2);

msPerDay = 24 * 60 * 60 * 1000
dbd = Math.floor((secondDate-firstDate)/ msPerDay) + 1;

Pls help... I have been thinking of solutions to solve that frustrating problem for some months already. ~:p

Thanks so very much if you can help!

[edit: moved by notepad]

Reply With Quote
  #2  
Old January 24th, 2003, 01:39 PM
filefrog filefrog is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: West Peoria, IL
Posts: 62 filefrog User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to filefrog
RE: Calculating difference between two dates in javascript

Try converting each date into the number of seconds since an arbitrary starting point (they usually use Jan 1, 1970), subtracting the larger number (more recent date) from the smaller number) and then convert that into whatever time quantity you need.

Reply With Quote
  #3  
Old January 27th, 2003, 08:39 AM
StrawBerry StrawBerry is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 11 StrawBerry User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Calculating difference between two dates in javascript

Hi filefrog,

thanks fr helping and i have solved the problem already.


Reply With Quote
  #4  
Old January 28th, 2003, 02:16 AM
filefrog filefrog is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: West Peoria, IL
Posts: 62 filefrog User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to filefrog
RE: Calculating difference between two dates in javascript

cool. how didja do it (just curious, and also in case anyone else is facing the same 'problem') ?

Reply With Quote
  #5  
Old February 8th, 2003, 02:00 AM
StrawBerry StrawBerry is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 11 StrawBerry User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Calculating difference between two dates in javascript

Hi FileFrog,

Here's the solution that i have managed to figured out:

var day1, day2;
var month1, month2;
var year1, year2;

value1 = form.datebox.value;
value2 = form.datebox2.value;

day1 = value1.substring (0, value1.indexOf ("/"));
month1 = value1.substring (value1.indexOf ("/")+1, value1.lastIndexOf ("/"));
year1 = value1.substring (value1.lastIndexOf ("/")+1, value1.length);

day2 = value2.substring (0, value2.indexOf ("/"));
month2 = value2.substring (value2.indexOf ("/")+1, value2.lastIndexOf ("/"));
year2 = value2.substring (value2.lastIndexOf ("/")+1, value2.length);

date1 = year1+"/"+month1+"/"+day1;
date2 = year2+"/"+month2+"/"+day2;

firstDate = Date.parse(date1)
secondDate= Date.parse(date2)

msPerDay = 24 * 60 * 60 * 1000
dbd = Math.round((secondDate.valueOf()-firstDate.valueOf())/ msPerDay) + 1;

Hope this helps!!

Sorry i was busy that didn't notice your next question.. :p



Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesClient Side Things > Calculating difference between two dates in javascript


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five &quot;checkpoints&quot; for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway