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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:00:49+00:00 2026-06-04T13:00:49+00:00

I want to subtract one date to another using php and display result in

  • 0

I want to subtract one date to another using php and display result in the days – hours – min – sec format. How i do this using php . I tried this using time stamp but it does not give proper values. please give suggestion

For ex : from date 2012-04-27 19:30:56 to date 2012-04-27 19:37:56

i used this code

if(strtotime($history['datetimestamp']) > strtotime($lasttime)) {

                 $totalelapsed1 = (strtotime($history['datetimestamp'])-strtotime($lasttime)); 




                     if($totalelapsed1 > 60 ) {
                         $sec = $totalelapsed1%60;
                         $min = round($totalelapsed1/60 , 0);

                         $minute = $min + $minute;
                         $second = $sec + $second;

                        // echo $min. " min " .$sec." sec";

                     } else {
                         //echo "0 min " . $totalelapsed1." sec";

                         $minute = 0 + $minute;
                         $second = $totalelapsed1 + $second;

                    }



                } else {
                     $minute = 0 + $minute;
                     $second = 0 + $second;
                    // echo "0 min 0 sec";
                }
  • 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-04T13:00:50+00:00Added an answer on June 4, 2026 at 1:00 pm

    From how to subtract two dates and times to get difference by VolkerK:

    You have to use like this:-

    <?php
    
    //$now = new DateTime(); // current date/time
    $now = new DateTime("2010-07-28 01:11:50");
    $ref = new DateTime("2010-07-30 05:56:40");
    $diff = $now->diff($ref);
    printf('%d days, %d hours, %d minutes', $diff->d, $diff->h, $diff->i);
    prints 2 days, 4 hours, 44 minutes
    

    see http://docs.php.net/datetime.diff

    edit: But you could also shift the problem more to the database side, e.g. by storing the expiration date/time in the table and then do a query like
    … WHERE key='7gedufgweufg' AND expires<Now()
    Many rdbms have reasonable/good support for date/time arithmetic.

    Link Url:- how to subtract two dates and times to get difference

    http://www.webpronews.com/calculating-the-difference-between-two-dates-using-php-2005-11

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

Sidebar

Related Questions

I want to subtract one integer from another, and the result should floor at
Put simply, I want to subtract one array from another. The arrays are arrays
Is it possible to subtract the values in one NSMutableArray from those in another
I've got a timedelta. I want the days, hours and minutes from that -
so in my app I want to subtract two dates. The first date is
I want to get the minimum values from two mappings and subtract one from
I'm using the following code to take the value of one field, subtract it
I have Array of time string like 10:10:12,12:10:34,05:23:11 this. I want to calculate less(min)
want to know why String behaves like value type while using ==. String s1
want to have a Hyperlink-Button in a gridView in which I can display a

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.