Answers for "php days count between two dates excluding weekends"

PHP
2

Get the number of days between two dates in PHP

$startDate = new DateTime("2019-10-27");
$endDate = new DateTime("2020-04-11");

$difference = $endDate->diff($startDate);
echo $difference->format("%a");
Posted by: Guest on January-14-2021
0

php count days excluding weekends

function sumDays($days = 0, $format = 'd/m/Y') {
    $incrementing = $days > 0;
    $days         = abs($days);
    $actualDate   = date('Y-m-d');

    while ($days > 0) {
        $tsDate    = strtotime($actualDate . ' ' . ($incrementing ? '+' : '-') . ' 1 days');
        $actualDate = date('Y-m-d', $tsDate);

        if (date('N', $tsDate) < 6) {
            $days--;
        }
    }

    return date($format, strtotime($actualDate));
}
Posted by: Guest on May-17-2021

Code answers related to "php days count between two dates excluding weekends"

Browse Popular Code Answers by Language