0

I have 2 time inputs as 7:07:02 and 7:00

How can I find the difference between these two,I prefer to use jquery, Is there any jquery plugins available for this ? ( please let me know if you know other solutions for this )

Thanks a lot

3
  • 1
    What would be the expected result in this case?
    – Gumbo
    Commented Dec 8, 2010 at 17:08
  • guys I expect 0:07:02 as output, thanks Commented Dec 8, 2010 at 17:43
  • It is basic math operations, what is hard about multiplying and dividing some numbers by 60? Commented Dec 8, 2010 at 17:51

2 Answers 2

1

I would recommend Date.js

(Date.parse('7:07:02') - Date.parse('7:00')) / 1000; // => 422 seconds
6
  • @matt why to use a any javascript library for this , we can just achieve with javascript right.
    – kobe
    Commented Dec 8, 2010 at 17:17
  • @gov it all boils down to his use cases. We can't read his mind, but already in his example he gives 2 different formats for time. Will it ever include a date? AM or PM? Who knows. I would ask you - why write all the JS to properly parse dates and times when someone else has already done the heavy lifting for you? Date functionality in JS is already pretty sparse. DateJS makes working with date and times in JS trivial.
    – Matt
    Commented Dec 8, 2010 at 17:22
  • sorry guys, first value : 7:00 second value : 7:07:02 result: 0:07:02 thank you Matt, hope you can fix this too Commented Dec 8, 2010 at 17:35
  • You want the result to be the string value "0:07:02" or a numerical value representing 7 minutes and 2 seconds?
    – Matt
    Commented Dec 8, 2010 at 17:39
  • either string value or numerical value,I just want to show the result on a input box after user types the second value, 7:07:02 .first value comes from database Thanks a again, Commented Dec 8, 2010 at 17:43
0

I don't think you want jquery. Just javascript will accomplish this. Change the two times to Dates and then add/subtract them as you like. Finally convert back to the date format that you want to use.

Not the answer you're looking for? Browse other questions tagged or ask your own question.