?
Solved

How do we add and subtract Time using javascript

Posted on 2006-04-20
2
Medium Priority
?
297 Views
Last Modified: 2010-07-27
How do we add/subtract time using javascript?

I have two textboxes which displays time in this format ( 9:15 AM ).
All i want to do is subtract time from these ( i.e. 9:15 AM from 10:40 AM )

Damu



0
Comment
Question by:ck_damu
2 Comments
 
LVL 8

Accepted Solution

by:
KennyTM earned 750 total points
ID: 16504856
Hi. Try

a = '9:15 AM';
b = '10:40 AM';

var dummy_date = '2000 Jan 1 ';
var da = new Date(dummy_date + a);
var db = new Date(dummy_date + b);
var milliseconds = db.getTime() - da.getTime();

alert (milliseconds/60000 + " minutes have passed!");
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 16504899
However watch it if the time is around daylight saving and goes over 2AM/3AM
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

809 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