Solved

Hours difference between 2 dates

Posted on 2011-02-16
9
315 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
[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
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
iterator/ListIterator approach 17 68
jboss wildfly 10.1 10 624
Which non-HTML GUI front end to use with Java? 3 67
collection output issue 9 96
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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 …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses

752 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