Solved

Hours difference between 2 dates

Posted on 2011-02-16
316 Views
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.

0
Question by:softbless
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 9

Accepted Solution

AriMc earned 100 total points
ID: 34911845
0

LVL 47

Assisted Solution

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

ID: 34911868
But I guess you have it in JavaScript ?
0

LVL 47

Expert Comment

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

LVL 47

Assisted Solution

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

ID: 34911914
0

LVL 92

Assisted Solution

objects earned 100 total points
ID: 34911921
0

LVL 86

Assisted Solution

CEHJ earned 100 total points
ID: 34914178
0

Author Closing Comment

ID: 34976884
thanks
0

Featured Post

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…