Click here to Skip to main content
15,880,364 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have done almost everything I found on the internet. I have been trying for the past two days but couldn't get the desire answer. I just want to subtract two times. example 22:00:00 - 00:30:00 = 21:30:00

What I have tried:

PHP
$hourToEatLastMeal = strtotime('00:30:00');
$hourToEatWorkout = strtotime('01:30:00');
$hourBetweenMeal = strtotime('07:30:00');
$lastMealRequested = strtotime($row['lastMeal']); //22:00:00 //value getting from query.

$startEating = $lastMealRequested - $hourToEatLastMeal ;//21:30:00 (want this answer)
$timeToEat = $startEating- $hourBetweenMeal; //14:00:00 (want this answer)
$whenToWorkout = $timeToEat - $hourToEatWorkout; //12:30:00 (want this answer)

$whenToWorkout = date("H:i:s",($whenToWorkout));//12:30:00 (want this answer)
$timeToEat = date("H:i:s",($timeToEat));//14:00:00 (want this answer)
$startEating = date("H:i:s",($startEating));//21:30:00  (want this answer)
Posted
Updated 12-Aug-20 6:37am

 
Share this answer
 
You can use PHP: DateTime::diff - Manual[^]
Example:
PHP
$start_t = new DateTime($start_time);
$current_t = new DateTime($current_time);
$difference = $start_t ->diff($current_t );
$return_time = $difference ->format('%H:%I:%S');
 
Share this answer
 
$diff = abs(time() - $time);

        $years = floor($diff / (365*60*60*24));  


        $months = floor(($diff - $years * 365*60*60*24) 
                                       / (30*60*60*24));  
          
          
        $days = floor(($diff - $years * 365*60*60*24 -  
                     $months*30*60*60*24)/ (60*60*24)); 
          
          
        $hours = floor(($diff - $years * 365*60*60*24  
               - $months*30*60*60*24 - $days*60*60*24) 
                                           / (60*60));  
          
        $minutes = floor(($diff - $years * 365*60*60*24  
                 - $months*30*60*60*24 - $days*60*60*24  
                                  - $hours*60*60)/ 60); 

        if ($minutes > 15 ) {
            $success = true;
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900