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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:14:48+00:00 2026-05-23T15:14:48+00:00

I have two times in my database: $time1 = 02:00:03; $time2 = 04:00:04; and

  • 0

I have two times in my database:

$time1 = "02:00:03";
$time2 = "04:00:04";

and I want to make add them $time1 + $time2 what is the best way to do that?

I have no problem with the diference cause I can do something like this:

$end = new DateTime($this->hora_final);
$start = new DateTime($this->hora_inicio);
$diff = $end->diff($start);

$diff->format('%H:%I:%S');

and it works perfectly… but i can’t seem to find a way to add them… any ideas?

Regards

  • 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-23T15:14:49+00:00Added an answer on May 23, 2026 at 3:14 pm

    DateTime::add(). It really doesn’t make much sense to add two dates, thus you cannot treat $time2 as DateTime, to add it to time1. Usually you would say something like 01.04. + 2 days, but not 01.04. + 02.00. The method accepts an object of type DateInterval. To create it I suggest to use something like

    list($hour, $min, $second) = explode(':', $time2);
    $interval = new DateInterval("PT{$hour}H{$min}M{$second}S");
    

    Now you should be able to add the interval to the date

    $x = new DateTime($time1);
    $y = $x->add($interval);
    

    (untested)

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

Sidebar

Related Questions

At my view I have two menus that I want to make dependent, namely,
I want to compare two times in VB.net: I have 1:42:21 PM and I
I want to make an app that allows users to add other users to
I have two times in PHP and I would like to determine the elapsed
I am trying to get a timer to count two times but I have
I have two arrays with time values in them in this format. 00:00:00 which
I have two variables: char charTime[] = TIME; char buf[] = SOMETHINGELSE; I want
I seemingly have two choices: Make my class implement IDisposable . Create my DbCommand
I have a site that uses classic ASP and a database in Access 2007
What's the best way to make small schema updates to your symfony/doctrine application? My

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.