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:
  #1  
Old January 24th, 2003, 01: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, 02: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: 3
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, 09: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, 03: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: 3
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, 03: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!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

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




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek