Solved

Hours difference between 2 dates

Posted on 2011-02-16
9
311 Views
Last Modified: 2012-05-11
Dear All,

I have this variable.

var myTodayDate = new Date();
var myDueDate='2010-11-31'

I want to know how many hours will be for : myDueDate - myTodayDate.

Please advise. Thanks      
0
Comment
Question by:softbless
9 Comments
 
LVL 9

Accepted Solution

by:
AriMc earned 100 total points
ID: 34911845
0
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 200 total points
ID: 34911854
There is probably some methd with Calendar
but the simple thig f=would be:

double hours = (double)(d1.getTime()-d2.getTime())/(60L*60L*1000L)
0
 
LVL 47

Expert Comment

by:for_yan
ID: 34911868
But I guess you have it in JavaScript ?
0
 
LVL 47

Expert Comment

by:for_yan
ID: 34911880
Actually date.getTime() should also work in JavaScript as milliseconds since 1970
only you don't have these long numbers,
probably simply

 (d1.getTime()-d2.getTime())/3600000

Then do you want to return back integer number of hours?
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 200 total points
ID: 34911894
with rounding it should be , I guess, like that;

 Math.round((d1.getTime()-d2.getTime())/3600000)
0
 
LVL 92

Expert Comment

by:objects
ID: 34911914
0
 
LVL 92

Assisted Solution

by:objects
objects earned 100 total points
ID: 34911921
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 100 total points
ID: 34914178
0
 

Author Closing Comment

by:softbless
ID: 34976884
thanks
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
solarwind tftp server 2 44
Non-recursive backtracking, using a stack 1 98
eclipse shortcuts 9 45
nextBoolean(double p) for Random class 3 35
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
The viewer will learn how to implement Singleton Design Pattern in Java.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now