1. Go to this page and download the library: Download brtriver/date-range 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/ */
brtriver / date-range example snippets
use Brtriver\DateRange\DateRange;
$range = new DateRange('2015-12-01', '2015-12-31');
$range = new DateRange(['2015-12-01', '2015-12-31']);
$start = new DateTime('2012-12-01');
$end = new DateTime('2012-12-31');
$range = new DateRange([$start, $end]);
try {
$range = new DateRange('tomorrow', 'today');
} catch (\InvalidArgumentException $e) {
echo $e->getMessage();
// end date is the day before than start date
}
# if you get start DateTime object.
$start = $range->getStart();
# if you get end DateTime object.
$end = $range->getEnd();
## check contains specific date
var_dump($range->contains('2015-12-10'));
// bool(true)
var_dump($range->contains('2017-01-10'));
// bool(false)
$range = new DateRange('2015-12-01', '2015-12-03');
$range->diff()->format('%R%a days');
// +2 days