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

  • Home
  • SEARCH
  • 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 3403644
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:17:10+00:00 2026-05-18T05:17:10+00:00

I am getting the time duration correctly for 24 hrs format but for 12

  • 0

I am getting the time duration correctly for 24 hrs format but for 12 hrs format I am getting error if i give 11:00 am to 1:00 pm. If I give 10:00 am to 11:00 am it will correctl and if I give 6:00 pm to 7:00 pm it will give correctly only in am to pm i m facing problem.

function autoChangeDuration() {
    var diff1 = "00:00";
    var start = document.getElementById("startTime").value;

    var end = document.getElementById("endTime").value;

    if (start > end) {
        document.getElementById("duration").value = diff1;
    } else {
        var space1 = start.split(' ');
        var space2 = end.split(' ');

        s = space1[0].split(':');
        e = space2[0].split(':');

        var diff;

        min = e[1] - s[1];
        hour_carry = 0;

        if (min < 0) {
            min += 60;
            hour_carry += 1;
        }

        hour = e[0] - s[0] - hour_carry;
        diff = hour + ":" + min;
        document.getElementById("duration").value = diff;
    }
  • 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-18T05:17:11+00:00Added an answer on May 18, 2026 at 5:17 am
    function toDate(s) {
    
        // the date doesn't matter, as long as they're the same, since we'll
        // just use them to compare. passing "10:20 pm" will yield 22:20.
        return new Date("2010/01/01 " + s);
    
    }
    
    function toTimeString(diffInMs) {
    
       // Math.max makes sure that you'll get '00:00' if start > end.
    
       var diffInMinutes = Math.max(0, Math.floor(diffInMs / 1000 / 60));
       var diffInHours = Math.max(0, Math.floor(diffInMinutes / 60));
    
       diffInMinutes = diffInMinutes % 60;
    
       return [
           ('0'+diffInHours).slice(-2),
           ('0'+diffInMinutes).slice(-2)
       ].join(':');
    
    }
    
    function autoChangeDuration()
    {
        var start = document.getElementById("startTime").value;
        var end = document.getElementById("endTime").value;
    
        start = toDate(start);
        end = toDate(end);
    
        var diff = (end - start);
    
        document.getElementById("duration").value = toTimeString(diff);
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting this error but only very occasionally. 99.9% of the time it
I'm getting an error here that says I haven't defined a method, but it
Windows has GetFileTime API which allows getting file time information by open file handle.
Can I get an object's name in run time (like getting an object's type
I'm getting this message each time I compile my project: RunIPhoneUnitTest.sh: line 92: 31389
I'm a long time hobbyist programmer interested in getting into web application development. I
I am just getting into ibatis with SqlMap for the first time and I
I'm just getting started working with foreign keys for the first time and I'm
I'm a long-time ActionScript 2 user, now getting started with ActionScript 3. The one
I'm getting some strange, intermittent, data aborts (< 5% of the time) in some

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.