Warning: Invalid argument supplied for foreach() in /home/jihswbiz/public_html/t6.gwilt.org/refDox.php on line 212
Docs-dateDiff

 

ReLoad

Keys


Functions

arraybrowsercolorcookiedatetimeDBdebugdeviceDSTequiverrorflagsfontformatgeo
holidayhtmlisjsonmathparsePHPprintsearchsortstringtabletexttracetype
VOTDweatherxml

Function  dateDiff   Lines 684-765 (81 lines) file  utils.php   Last mod: Fri 2021-05-14 21:45:07

function dateDiff $d1$d2 )
        {       
# $d1 - $d2
#-k     datetime
#-      compares two timestamps and returns array with differences (year, month, day, hour, minute, second)
#-s     See also: dateRange formatTime secondsToInterval since time2secs date


//check higher timestamp and switch if neccessary
        
if ($d1 $d2)
                {
                
$temp $d2;
                
$d2 $d1;
                
$d1 $temp;
                }
        else
                {
                
$temp $d1//temp can be used for day count if required
                
}

        
$d1 date_parse(date("Y-m-d H:i:s",$d1));
        
$d2 date_parse(date("Y-m-d H:i:s",$d2));

//seconds
        
if ($d1['second'] >= $d2['second'])
                {
                
$diff['second'] = $d1['second'] - $d2['second'];
                }
        else
                {
                
$d1['minute']--;
                
$diff['second'] = 60-$d2['second']+$d1['second'];
                }

//minutes
        
if ($d1['minute'] >= $d2['minute'])
                {
                
$diff['minute'] = $d1['minute'] - $d2['minute'];
                }
        else
                {
                
$d1['hour']--;
                
$diff['minute'] = 60-$d2['minute']+$d1['minute'];
                }

//hours
        
if ($d1['hour'] >= $d2['hour'])
                {
                
$diff['hour'] = $d1['hour'] - $d2['hour'];
                }
        else
                {
                
$d1['day']--;
                
$diff['hour'] = 24-$d2['hour']+$d1['hour'];
                }

//days
        
if ($d1['day'] >= $d2['day'])
                {
                
$diff['day'] = $d1['day'] - $d2['day'];
                }
        else
                {
                
$d1['month']--;
                
$diff['day'] = date("t",$temp)-$d2['day']+$d1['day'];
                }

//months
        
if ($d1['month'] >= $d2['month'])
                {
                
$diff['month'] = $d1['month'] - $d2['month'];
                }
        else
                {
                
$d1['year']--;
                
$diff['month'] = 12-$d2['month']+$d1['month'];
                }

//years
        
$diff['year'] = $d1['year'] - $d2['year'];
        return 
$diff;
        }

?>