PHP code example of code16 / carbon-business-days

1. Go to this page and download the library: Download code16/carbon-business-days library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

code16 / carbon-business-days example snippets


$date = new BusinessDays();
    
// Set holidays (2018-1-1 is a Monday)
$date->addHoliday(Carbon::createFromDate(2018, 1, 1));
    
// Should return 9
$days = $date->daysBetween(
    Carbon::createFromDate(2018, 1, 1),
    Carbon::createFromDate(2018, 1, 15)
);
    
// Set a closed period (whole 2nd week)
$date->addClosedPeriod(
    Carbon::createFromDate(2018, 1, 8),
    Carbon::createFromDate(2018, 1, 12)
);

// Should return 5
$days = $date->daysBetween(
    Carbon::createFromDate(2018, 1, 1),
    Carbon::createFromDate(2018, 1, 15)
);

$date->setWeekendDays([Carbon::SUNDAY, Carbon::MONDAY]);

$newDate = $date->addDaysTo(
    Carbon::createFromDate(2018, 5, 14), 
    10
);
$newDate = $date->subDaysFrom(
    Carbon::createFromDate(2018, 5, 14), 
    10
);