Solved

Hours difference between 2 dates

Posted on 2011-02-16
9
314 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
use lov values 2 63
going to wrong jsp page 2 33
ejb entity bean example issue 2 17
Java basic valueOf question 1 29
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

828 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