kschu91 / date-range
There is no license information available for the latest version (dev-master) of this package.
A small PHP library to extract date ranges out of a list of dates.
dev-master
2018-10-07 20:11 UTC
Requires
- php: ^7.1
Requires (Dev)
- phpunit/phpunit: ^7.3
- squizlabs/php_codesniffer: ^3.3
This package is auto-updated.
Last update: 2024-12-08 10:26:19 UTC
README
PHP Date Range
A small PHP library to extract date ranges out of a list of dates.
Installation
composer require "kschu91/date-range"
If you are not familiar with composer: composer basic usage
Requirements
- PHP >= 7.1
Basic Usage
$datePeriods = (new DateRangeInterval(new \DateInterval('P1D'), $dates))->getDatePeriods();
Example
$dates = [ new \DateTime('2018-09-02'), new \DateTime('2018-09-03'), new \DateTime('2018-09-04'), new \DateTime('2018-09-08'), new \DateTime('2018-10-02'), new \DateTime('2018-10-03'), ]; $range = new DateRangeInterval(new \DateInterval('P1D'), $dates); $datePeriods = $range->getDatePeriods(); foreach ($datePeriods as $datePeriod) { echo $datePeriod->start->format('Y-m-d') . ' - ' . $datePeriod->end->format('Y-m-d') . PHP_EOL; }
will output:
2018-09-02 - 2018-09-04
2018-09-08 - 2018-09-08
2018-10-02 - 2018-10-03