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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:07:39+00:00 2026-05-16T04:07:39+00:00

So what I am trying to do is add two strings together in the

  • 0

So what I am trying to do is add two strings together in the form of military time. Here is the example.

Time1 = “01:00”;
Time2 = “04:30”;

Adding the two together would produce “05:30”. This seems incredibly simple, but it has been a long long day for a new learner. Any help would be greatly appreciated.

  • 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-16T04:07:39+00:00Added an answer on May 16, 2026 at 4:07 am

    You can do something like this in PHP 5.3:

    $d = new DateTime("01:00");
    $f = $d->add(new DateInterval("PT04H30M"));
    echo $f->format("H:i"); //outputs 05:30
    

    Converting 04:30 to PT04H30M should be trivial. Note that whether this is actually what you want depends on what you mean by “04:30”. This code may or may not sum 4*60+30 minutes to the actual time.

    If you mean “4 hours and 30 minutes on the clock” this is always correct. However, if you mean “4*60+30 minutes”, it depends on the day and timezone. Example:

    $d = new DateTime("2010-03-28 01:00 Europe/Lisbon");
    $f = $d->setTimestamp($d->getTimestamp() + (4*60+30)*60);
    echo $f->format("H:i"); //outputs 06:30 due to DST
    

    An alternate implementation of the last case (assuming current day and default timezone) for PHP 5.2 is

    echo date("H:i", strtotime("+4 hours +30 mins", strtotime("01:00")));
    

    For the first case, we must do:

    date_default_timezone_set("UTC");
    echo date("H:i", strtotime("+4 hours +30 mins", strtotime("01:00")));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to add together two lists so the first item of one
I'm trying to add two strings with snprintf but apparently i dont know what
I am trying to add spacing to align text in between two strings vars
I am trying to add two numbers together from EditText fields. So far I
Trying to add two integer variables together, however, I can't seem to figure it
I'm trying to compare two strings and as output I would like a count
I am trying to do this List<String> stringList = new ArrayList<String>(); stringList.add(one); stringList.add(two); stringList.add(three);
I'm trying to add two object that they are in the same class. In
I'm trying to add two inputs to a QTCaptureSession in the following: mainSession =
I am trying to add two larger binary numbers (i.e. number of bits are

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.