Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4324888
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:11:36+00:00 2026-05-21T09:11:36+00:00

I want to find difference between two time-components, but I am not getting what

  • 0

I want to find difference between two time-components, but I am not getting what I want!

I have 2 drop-down list components in a form,

here is my code:

input set 1:
timefrm_ 4 -> 18:00  
timeto_4 -->  23: 00

input set 2 : 
timefrm_ 4 -> 23:00

timeto_4 --> 01 : 00

JavaScript code:

function time_diif4()
{
 var timespan4from = HMStoSec1(timefrm_4);

 var timespan4to = HMStoSec1(timeto_4);

 var timespan_4 =  timespan4to - timespan4from ;

 var diff4 = convertMinutes(timespan_4);


               alert(timespan4from);
               alert(timespan4to);
               alert(timespan_4);
               alert(diff4);
}


var secondsPerMinute = 60;

var minutesPerHour = 60;

function HMStoSec1(T) 
   { 
// h:m:s

  var A = T.split(/\D+/) ; 

  return ((A[0]*60 + +A[1])*60 ) 

    }

function convertMinutes(intSeconds) 
{
return Math.floor(intSeconds/secondsPerMinute);
}

my output (as alert) is:

for input set 1:

64800 (in seconds)

82800 (in seconds)

18000 (in seconds)

300 (in minutes) — 5 hours ( 18:00
to 23:00)

for input set 2:

82800

5400

-77400 ( error it should be next day)

-1290

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T09:11:37+00:00Added an answer on May 21, 2026 at 9:11 am

    just find the remaining value in division to a day minutes.

    function convertMinutes(intSeconds) { 
       var result = Math.floor(intSeconds/secondsPerMinute); 
       while(result < 0)
          result = result + minutesPerHour * 24;
    
       return result;
    }
    

    when the start time is greater than finish time then it means that finish time belongs to next day. this code will solver this problem. but if you don’t want this to happen, you should prevent user to selecting this data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to find time difference between two date and then compare the difference
I want to find out the difference between two Dates (in terms of minutes)
I have two NSDate objects and I want the difference between the two and
Let's say I want to find out the difference in seconds between two times.
I am not able to find actual differences between these two Java EE servers.
so I have these two time stamps in PHP 1253339331 1253338959 I want to
Is there any way find difference between two cs files. I already ask question
I want to know what the difference between these two foreignkey definitions are. (1)
Help me please to find out what's the difference between these two code snippets:
I have two examples here, only difference between these two example are one uses

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.