Geting Difference between two datae and time (Example 2) startPHP-022


		<?php
   $DateTime1 = '2020-07-26 18:25:45';
   //$DateTime1 = date("Y-m-d H:i:s");
   $DateTime2   = '02/26/20 18:47:33';

         ///////////////////////////////////////////
        function dateTimDiffAll($date1,$date2){
          $firstTime = strtotime($date1);
          $secondTime = strtotime($date2);
          $seconds = abs($firstTime - $secondTime);
  
                
          $dif=array();
          $minuteS = 60;
          $hourS   = 60*60;
          $dayS    = 60*60*24;
          $monthS  = 60*60*24*30;
          $yearS   = 60*60*24*30*365;          
                
    $dif['y'] = floor($seconds /$yearS);
    $dif['M'] = floor( ($seconds - $yearS*$dif['y']) /$monthS);
    $dif['d'] = floor( ($seconds - $yearS*$dif['y'] 
                        - $monthS*$dif['M'] ) /$dayS); 
    $dif['h'] = floor( ($seconds - $yearS*$dif['y'] 
                        - $monthS*$dif['M'] 
                        - $dayS*$dif['d'] ) /$hourS);    
    $dif['m'] = floor( ($seconds - $yearS*$dif['y'] 
                        - $monthS*$dif['M'] 
                        - $dayS*$dif['d'] 
                        - $hourS*$dif['h'] ) /$minuteS); 
    $dif['s'] = floor( ($seconds - $yearS*$dif['y'] 
                        - $monthS*$dif['M'] 
                        - $dayS*$dif['d'] 
                        - $hourS*$dif['h']
                        - $minuteS*$dif['m']) );     
  
    return $dif;
        }/////////////////////////////////////////dateDiff($old,$new)  
        //now date("Y-m-d H:i:s");
 $triggerTime =array(
     's'=>12,
     'm'=>38,
     'h'=>23,
     'd'=>0,
     'M'=>5,
     'y'=>0
     );      
   ?>
<!DOCTYPE html>

<html>
    <head>
        <meta charset="UTF-8">
        <title>StartPHP 022: Time and Date Difference Code 2</title>
    </head>
    <body>
        <h1>Time Difference</h1>

        <span style="font-size:1m">First date and time: <?php echo $DateTime1?></span><br/>
        <span style="font-size:1m">Second date and time: <?php echo $DateTime2?></span><br/>
       Seconds: <?php echo  dateTimDiffAll($DateTime1,$DateTime2)['s']?><br/>
       and Minutes: <?php echo  dateTimDiffAll($DateTime1,$DateTime2)['m']?><br/> 
       and Hours: <?php echo  dateTimDiffAll($DateTime1,$DateTime2)['h']?><br/>    
       and days : <?php echo  dateTimDiffAll($DateTime1,$DateTime2)['d']?><br/> 
       and Months: <?php echo  dateTimDiffAll($DateTime1,$DateTime2)['M']?><br/> 
       and Years: <?php echo  dateTimDiffAll($DateTime1,$DateTime2)['y']?><br/> 


    </body>
</html>