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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:19:05+00:00 2026-06-15T00:19:05+00:00

i am implementing one application in which i have to display a time difference

  • 0

i am implementing one application in which i have to display a time difference in total hour from end date to start date. suppose i have both start date and end date in timestamp.so how i will get the difference of date in total hour ?
now i am using the below code

 $intervalo = date_diff(date_create(), date_create($end));
    pr($intervalo);

and the output is like

DateInterval Object
(
    [y] => 0
    [m] => 1
    [d] => 4
    [h] => 18
    [i] => 41
    [s] => 2
    [invert] => 0
    [days] => 34
)

the above code show me the total hour baut the end date is greater then 1month it shows 1m in array . but i only want total number of hour only
can any one help me ?
thanks in advance

  • 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-15T00:19:06+00:00Added an answer on June 15, 2026 at 12:19 am

    Don’t use date_diff. Convert the dates to timestamps (which represent seconds), subtract the two, and divide by 3600.

    $x = date_create();
    $y = date_create($end)
    $hours = ($y->getTimestamp() - $x->getTimestamp()) / 3600;
    

    If you want hours, minutes, and seconds:

    $x = date_create();
    $y = date_create($end)
    $diff = ($y->getTimestamp() - $x->getTimestamp());
    
    $seconds = $diff % 60;
    $diff    = (int)($diff / 60);
    $minutes = $diff % 60;
    $diff    = (int)($diff / 60);
    $hours   = $diff;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am implementing one graph related app. In that when application start i am
I have a django application which has one main table/model which references various 'lookup'
I have a service application which I will be soon implementing a log file.
I have an ASP.NET MVC4 website implementing a REST API, which I'm consuming from
I have a web application from which emails should be sent after specific actions.
I have an ETL application which extracts data from a source database (for which
I am implementing one iPhone animal application. In which I want to add face
I have an interface which implementing classes export via MEF in my application. The
i am implementing one app related to animation. My require ment is, i have
I have two Java interfaces and one implementing class. (I have used Eclipse to

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.