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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:37:29+00:00 2026-06-17T16:37:29+00:00

I am trying to write a function that will add time stamps together to

  • 0

I am trying to write a function that will add time stamps together to get a sum of all. For example:11:30 + 12:00 + 15:35 = 39:05 I am unsure of how to accomplish this. I have included code below that I have tried but it does not give the desired result:

$TotalTime = strtotime($data['TotalSunday']) + strtotime($data['TotalMonday']) 
    + strtotime($data['TotalTuesday'])
    + strtotime($data['TotalWednesday'])    + strtotime($data['TotalThursday'])
    + strtotime($data['TotalFriday']) + strtotime($data['TotalSaturday']);
    $data['TotalTime'] = gmdate("h:i", $TotalTime);
  • 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-06-17T16:37:30+00:00Added an answer on June 17, 2026 at 4:37 pm

    The problem is the following, you do want to add “times”, but in fact you are creating the sum of “dates”. strtotime expects two parameters: #1 is a date, #2 is a offset (if not given, it is “now”).

    This is merely a hack, and I’m not sure if anyone would use it like that, but it works:

    <?php
    
        $time1 = strtotime("00:25Z", 0);
        $time2 = strtotime("23:20:05Z", 0);
    
        $sumTime = $time1 + $time2;
    
        $hours = $sumTime / 3600;
        $minutes = ($sumTime % 3600) / 60;
    
        echo sprintf("%d:%d", $hours, $minutes); // Outputs: 23:45
    
    ?>
    

    By setting the second parameter to 0, and providing the datetime parameter with an additional Z (for Zulu time, or UTC), times up to 23:59:59 are parsed correctly in seconds.

    So if you really want to rely on strtotime, use it like that.

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

Sidebar

Related Questions

I'm trying to write a function that will return all the available cars for
I'm trying to write an extension method that will add the function HasFactor to
I'm trying to write a function in jQuery that will add a class to
I'm trying to write a Python script that will get the md5sum of all
I am trying to write a function that will allow me to browse for
I'm trying to write a function that will: If there is no region selected,
i am trying to write a function that will make DataRow[column] return nullable typed
I'm trying to write a function that will let me red-shift or blue-shift a
I am trying to write a function that will filter a list of tuples
I am trying to write a function that will: Disable the submit button when

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.