<?php 
include('dbconnect.php');
function computeMonth($date1, $date2, $differenceFormat){

    // $differenceFormat = '%d';
     $datetime1 = date_create($date1);
     $datetime2 = date_create($date2);
 
     $interval = date_diff($datetime1, $datetime2);
 
    return $interval->format($differenceFormat);
 
 }

$sql = $conn->query('SELECT *,pto.empid as "employee_id" FROM pto JOIN empdetails ON pto.empid = empdetails.detailid WHERE status="Inactive" AND name="Paid Time Off" ');
while ($row= $sql->fetch_assoc()) {

   

    

    if(date('Y', strtotime($row['hireddate']))  == date('Y') ){

        $month_dur = computeMonth($row['inactivedate'], $row['hireddate'],'%m');
        echo $row['employee_id'].'-'.$month_dur.'|'.$row['hireddate'].' - '.$row['inactivedate'].'<br>';
        
    }else{
        $Y_inactive = date('Y', strtotime($row['inactivedate'])) ;
        $Y_hire = date('Y', strtotime($row['inactivedate'])).'-01-'.date('d', strtotime($row['hireddate']));
        $month_dur = computeMonth($row['inactivedate'], $Y_hire,'%m')+1;
        echo $row['employee_id'].'-'.$month_dur.'|'.$Y_hire.' - '.$row['inactivedate'].'<br>';
        
    }
    $ptoearned =  $row['multiplier'] * $month_dur;
    $availablepto = $ptoearned - $row['usedpto'];

    $conn->query("UPDATE pto SET ptoearned =$ptoearned, availablepto=$availablepto  WHERE empid='".$row['employee_id']."' AND name='Paid Time Off'  ");
    # code...
}



?>