Hi Coders, am working on a function to calculate the balance leave in a year using php. For example, if leave entitlement in a year is 20 days, so if a staff takes 1 day leave, the balance leave will return 19 days. Below is the code but am not sure if this is correct? Thanks.

<?php

 // Create a function to count leave balance.

class Leave {
    public $leave_entitlement;
    public $start_date;
    public $end_date;
    public $leave_balance;   
    public $difference;
    public $diff;

    public function days_taken($startDate='Today', $endDate='Today')
    {
        $start_date = new DateTime($startDate);
        $end_date = new DateTime($endDate);
        $diff = $end_date->diff($start_date);
        return $diff->days;
    }

    public function calculateLeaveBal($leave_entitlement,$difference) 
    {      

        $this->difference=$this->days_taken();
        $this->leave_entitlement=$leave_entitlement;
        $leave_balance=$leave_entitlement-$difference;     
        return $leave_balance;

    }       
}

$leave1 = new Leave();
$leave1->days_taken('Today','Tomorrow');
echo $leave1->calculateLeaveBal(20,1);    

?>