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 4063808
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:46:27+00:00 2026-05-20T15:46:27+00:00

I have two values that are used for the amount of time it will

  • 0

I have two values that are used for the amount of time it will take to complete a task. How can I add these values together to come up with a total number of hours and minutes, but still have the value account for 60 minutes equalling one hour?

The two values I’d like to get the sum of and the total value are in HH:MM (00:00) format.

Thanks!

  • 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-20T15:46:28+00:00Added an answer on May 20, 2026 at 3:46 pm

    Here’s something I had laying around. It allows for an infinite number of arguments, so you could have addTime('01:00') or addTime('01:00', '02:00', '03:00', '04:00'), etc. It’s three functions long because it also verifies if the times entered are properly formatted, and if not, then it formats them. (E.g. Ensures that minutes is 2 digits long, and if hours is 1 digit long, then pad it with one zero, etc.)

    You can play with it here: http://jsfiddle.net/WyxwU/

    It’s also here:

    var totalTime = addTime('12:34', '56:12', '78:45');
    document.write(totalTime);
    
    function addTime()
    {
        if (arguments.length < 2)
        {
            if (arguments.length == 1 && isFormattedDate(arguments[0])) return arguments[0];
            else return false;
        }
    
        var time1Split, time2Split, totalHours, totalMinutes;
        if (isFormattedDate(arguments[0])) var totalTime = arguments[0];
        else return false;
    
        for (var i = 1; i < arguments.length; i++)
        {
            // Add them up
            time1Split = totalTime.split(':');
            time2Split = arguments[i].split(':');
    
            totalHours = parseInt(time1Split[0]) + parseInt(time2Split[0]);
            totalMinutes = parseInt(time1Split[1]) + parseInt(time2Split[1]);
    
            // If total minutes is more than 59, then convert to hours and minutes
            if (totalMinutes > 59)
            {
                totalHours += Math.floor(totalMinutes / 60);
                totalMinutes = totalMinutes % 60;
            }
    
            totalTime = totalHours + ':' + padWithZeros(totalMinutes);
        }
    
        return totalTime;
    }
    
    function isFormattedDate(date)
    {
        var splitDate = date.split(':');
        if (splitDate.length == 2 && (parseInt(splitDate[0]) + '').length <= 2 && (parseInt(splitDate[1]) + '').length <= 2) return true;
        else return false;
    }
    
    function padWithZeros(number)
    {
        var lengthOfNumber = (parseInt(number) + '').length;
        if (lengthOfNumber == 2) return number;
        else if (lengthOfNumber == 1) return '0' + number;
        else if (lengthOfNumber == 0) return '00';
        else return false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function that returns two values in a list. Both values need
I have two columns in a table that are populated with integer values. For
I have created two functions that sum and subtract the numeric values of two
I have a two-dimension ArrayList that contains double values: ArrayList<ArrayList<Double>> data = new ArrayList<ArrayList<Double>>();
I have an IF statement that consists of two separate function calls passing values
Dictionary cannot have two values with same key. please tell which logic/algorithm being used
In my application I have two queries which will be quite frequently used. The
I have two separate views that both show multiple lists of values. Both views
I have two arrays of values that I would like to combine - but
If I have two strings that are identical in value, is it guaranteed that

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.