Hi Hafiz i hope you are doing well, as i can see that when you declare $task_end_date variable you declared it as a string and $flyingdate you use date class what i recommend is to use date class in both variables, so you can calculate the difference in days between two dates there is the code i recommend you to use :
$flyingdate = new DateTime();
$task_end_date = new DateTime('2023-05-15');
// To calculate the difference between the dates
$interval = $flyingdate->diff($task_end_date);
// Change the difference to days format
$delays = $interval->format('%r%a');
// Check if the difference is negative
if ($delays < 0) {
$delays = 0;
}
// Display the delays
echo "Delays: $delays days";
As you can see in this code,we have DateTime objects for the flying date and the task end date. Then, we calculate the difference between the two dates using the diff() method. We use the %r%a format to get the signed difference in days, then we use a condition that check if the date difference in negative.
have a good day sir .