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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:17:53+00:00 2026-05-12T11:17:53+00:00

I have two times in PHP and I would like to determine the elapsed

  • 0

I have two times in PHP and I would like to determine the elapsed hours and minutes. For instance:

8:30 to 10:00 would be 1:30

  • 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-12T11:17:53+00:00Added an answer on May 12, 2026 at 11:17 am

    A solution might be to use strtotime to convert your dates/times to timestamps :

    $first_str = '8:30';
    $first_ts = strtotime($first_str);
    
    $second_str = '10:00';
    $second_ts = strtotime($second_str);
    

    And, then, do the difference :

    $difference_seconds = abs($second_ts - $first_ts);
    

    And get the result in minutes or hours :

    $difference_minutes = $difference_seconds / 60;
    $difference_hours = $difference_minutes / 60;
    var_dump($difference_minutes, $difference_hours);
    

    You’ll get :

    int 90
    float 1.5
    

    What you now have to find out is how to display that 😉

    (edit after thinking a bit more)

    A possibility to display the difference might be using the date function ; something like this should do :

    date_default_timezone_set('UTC');
    
    $date = date('H:i', $difference_seconds);
    var_dump($date);
    

    And I’m getting :

    string '01:30' (length=5)
    

    Note that, on my system, I had to use date_default_timezone_set to set the timezone to UTC — else, I was getting “02:30”, instead of “01:30” — probably because I’m in France, and FR is the locale of my system…

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

Sidebar

Related Questions

I have a PHP application using a MySQL database. I would like to prevent
i have two files:(localhost/template/) index.php template.php each time when i create an article(an article
I want to compare two times in VB.net: I have 1:42:21 PM and I
I have two tables like of this structure: content (content_id, content_type, user_id, time, comment_count)
I would like to know what would happen if I have a code like
I know questions like this have been asked numerous times, but not quite this
i need to do this in php lets say i have [1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,3,4,5,5,5,5,5,5,5,5,5,5,5,9,9,9,9,9] i would
I am using PHP and MySQL. I have two tables, one for customers, and
Example: I have some text, like this php code if(empty($condition)) { // work here...
I have two arrays with time values in them in this format. 00:00:00 which

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.