javascript time between two times

You can just subtract the hours right away doing it this way

var valuestart = $("select[name='timestart']").val();
var valuestop = $("select[name='timestop']").val();

//create date format          
var timeStart = new Date("01/01/2007 " + valuestart).getHours();
var timeEnd = new Date("01/01/2007 " + valuestop).getHours();

var hourDiff = timeEnd - timeStart;             
Here's the working fiddle http://jsfiddle.net/VnwF7/4/

UPDATE - to calculate if we are including the next day. Just add the following if block

 if (hourDiff < 0) {
    hourDiff = 24 + hourDiff;
 }
http://jsfiddle.net/gfvhqat9/

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
javascript find time difference between two times current time is between two times n javascript time is in between two time in js time is in between two time injs Check if time is between two times in js Check if current time is between two given times in JavaScript js calculate difference between two times check if current time is between two times js javascript get current time and check if times is between two timestamps between two times javascript javascript difference minutes between to times difference between two timestamps in seconds javascript seconds between two times javascript difference between two timestamps in seconds javascript how to check if the current time is between two times javascript how to calculate difference between two times in js javascript elapsed time between two times javascript duration between two times javascript get duration in hours between two timestamps javascript difference between two times how to calculate difference between 2 times js javascript count time difference time difference between two times in javascript find time between two times javascript make all possible time in js between two time js difference between times javascript calculate difference between two times in seconds javascript generate times between two times if is between two times javascript how to check current time is in between two times in jav ascript get difference between two times in javascript javascript get seconds between two times javascript if time is between two times time between two timestamps javascript minutes between two times javascript calculate time between two timestamps js javascript if time between two times javascript is time between two times javascript calculate time between two times javascript calculate time difference between two times js time between 2 times javascript check between two times check if current time is between two times javascript javascript timestamp difference in hours how to check if the time is between 2 times in js get time difference between two times in js javascript calculate time difference JavaScript calculate time difference between two times in seconds how to get difference between two times in javascript calculate time difference from timestamp in javascript time difference between two time in javascript time difference between two timein javascript calculate the time difference between two times in minutes in javascript calculate time difference javascript calculate time difference between two times javascript js time between two timeslots calculate total time between two times in javascript javascript difference between times javascript get duration between two timestamps how to get time timestamp time difference in javascript javascript check time between two times javascript time difference between two times javascript time now between two times set time between 2 function js js find seconds between two times how to check given time is between 2 time in javascript js difference between two times how to calculate time difference between two times in javascript check time between two times javascript javascript difference between two timestamp hours how to calculate time difference in javascript time difference between two times javascript get time difference between two timestamps javascript Check if time is between two times JavaScript difference between two times in javascript calculate time difference between two times in javascript es6 javascript get time difference between two times js check time between two timestamp calculate time difference in javascript javascript calculate time difference between two timestamps calculate time difference between two times in javascript javascript time between two timestamps javascript number of seconds between two timestamps get total time between two times javascript finding the time difference between 2 times in minutes javascript js timestamp difference in years calculate duration between two times javascript calculate difference between two times in javascript javascript check if time is between two times calculate time difference between two times js how to check if time is between two times in javascript How to calculate the number of time between two time data in javascript? Difference between two times javascript javascript time between two times
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source