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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:27:26+00:00 2026-06-15T07:27:26+00:00

Possible Duplicate: Time diff in minutes between 2 dates php date_diff in hours i

  • 0

Possible Duplicate:
Time diff in minutes between 2 dates
php date_diff in hours

i have:

$datetime1 = new DateTime('2012-12-01 10:40:00');
$datetime2 = new DateTime('2012-12-03 12:00:00');
$interval = $datetime1->diff($datetime2);
echo $interval->format('%1 day %h hours %i minutes');

this working ok, but how can i show only hours and minutes? For this example should be:

49 hours 10 minutes

  • 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-15T07:27:28+00:00Added an answer on June 15, 2026 at 7:27 am

    From the PHP manual:

    Note:

    The DateInterval::format() method does not recalculate carry over points in time strings nor in date segments. This is expected because it is not possible to overflow values like “32 days” which could be interpreted as anything from “1 month and 4 days” to “1 month and 1 day”.

    In other words, the DateInterval class won’t do what you’re asking for on its own; you’d have to do the calculation yourself.

    Something like this should do it:

    $hours = $interval->h + ($interval->d*24);
    print "{$hours} hours ".$interval->format('%i minutes');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: PHP date time Trying to add one second to a datetime that
Possible Duplicate: PHP/MySQL - Format date/time I have input field (name:day1 and varchar) to
Possible Duplicate: How to compare two time in PHP Hi I am new in
Possible Duplicate: How can I specify the latest time of day with DateTime I
Possible Duplicate: How to switch an Application between Themed and not Themed at run-time?
Possible Duplicate: Real-time Pitch Shifting on the iPhone i have already found the answer
Possible Duplicate: What date/time functions to use for PHP 5.2 I want to add
Possible Duplicate: How to convert a time to a string I have a variable
Possible Duplicate: Calculate date/time difference in java I am a new on Android and
Possible Duplicate: Get GMT Time in Java I have taken the reference of the

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.