0

I have two dates that belong to consecutive months, and I want to calculate the difference and how many days per month were taken. Example $start='26102022', $end='06112022'. what Im doing so far to get the number of days per month is :

$lastOfCurrentMonth=strtotime(date("Ymt",strtotime($val['datekey_start'])));
$iDays1 = numberOfWorkingdays($start, $lastOfCurrentMonth);
$iDays2 = numberOfWorkingdays($lastOfCurrentMonth, $end);
   
public function number_of_working_days($startDate, $endDate, $uid)
{
    $workingDays = 0;
    $startTimestamp = $startDate;
    $endTimestamp = $endDate;

//working days fct

public workingDays($start,$end) {
    $workingDays = 0;
    for ($i = $start; $i <= $end; $i = $i + (60 * 60 * 24)) {
        if (date("N", $i) <= 5) $workingDays = $workingDays + 1;
    }
    return $workingDays;
}

the count is sometimes 1 day shorter (so I just cant add 1) I was wondering is it the timestamp could different format give me different timestamp for the same date? and how can I make the $lastDayOfCurrent Month has the same format as 'Ymd' before using it to count days?

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
mouna
  • 73
  • 1
  • 6
  • not really, I dont need the difference but the difference per month. I need to know how many days belong to Oct and to Nov. – mouna Aug 31 '22 at 14:03
  • `$days_in_october = cal_days_in_month(CAL_GREGORIAN, 10, 2020);` = 31 – Markus Zeller Aug 31 '22 at 14:22
  • the calculations Im trying to get here is : oct-> 4 days and Nov->4 days and this should be dynamic for any different months I feed the function. but for some reason it s giving me Oct->3 and Nov->5 as if 31 oct is seen as a day of nov for some reason – mouna Aug 31 '22 at 14:57

0 Answers0