I want to count the total number of days between two date.
Note: I am not talking about the difference between two date
I found lots of answer on google and Stack Overflow. I am sharing here
$now = time(); // or your date as well
$your_date = strtotime("2018-06-01");
$datediff = $now - $your_date;
echo round($datediff / (60 * 60 * 24));
Output is 9
$now = strtotime("2018-06-09");
$your_date = strtotime("2018-06-01");
$datediff = $now - $your_date;
echo $numberDays= round($datediff / (60 * 60 * 24));
Output is 8
$dStart = new DateTime('2018-06-01');
$dEnd = new DateTime('2018-06-09');
$dDiff = $dStart->diff($dEnd);
echo $dDiff->days;
Output is 8
$date1=date_create("2018-06-01");
$date2=date_create("2018-06-09");
$diff=date_diff($date1,$date2);
echo $diff->format("%a");
Output is 8
$startTimeStamp = strtotime("2018-06-01");
$endTimeStamp = strtotime("2018-06-09");
$timeDiff = abs($endTimeStamp - $startTimeStamp);
$numberDays = $timeDiff/86400; // 86400 seconds in one day
// and you might want to convert to integer
echo $numberDays = intval($numberDays);
Output is 8
The correct answer for me is the first one 9 because it displays the total number of days from 1 to 9, not a difference.
I just want to know how to get the count because I don't want to use the time() because it's taking the current date.
For example: If I select the first date 2018-05-01 and my second date in 2018-05-31. So total days is 31, not 30.
Example: I am working on a project which is related to the working days and salary. So employee will select the date. for example. I am the employee and in the last month May, I select the date 2018-05-01 and 2018-05-31 so I have to display the total working days.So the according to the date I worked 31 days and using above code in the question I am getting 30 days.
Hope you understand my issue. Would you help me out in this?