`$flyingdate = date('Y-m-d H:i:s');
$task_end_date = '2023-05-15';
$delays = ($flyingdate - $task_end_date);`
Problem is that, String variables can not no be changed,
I tried with date difference and string comparison function but useless
It can not tell the exact difference of days i.e. actually telling delays of days from flying to task end date,
I want difference in term of days(store in $delays) and also condition should be
delays set to zero , if days are negative;
2
Answers
You can do like this, time() returns the current timestamp, strtotime also returns timestamp, so substracting both and converting the seconds to days
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 :
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 .