https://github.com/kschu91/date-range
A small PHP library to extract date ranges out of a list of dates.
https://github.com/kschu91/date-range
Last synced: 4 months ago
JSON representation
A small PHP library to extract date ranges out of a list of dates.
- Host: GitHub
- URL: https://github.com/kschu91/date-range
- Owner: kschu91
- Created: 2018-10-07T20:04:03.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-10-07T20:11:52.000Z (over 6 years ago)
- Last Synced: 2024-12-27T09:29:02.926Z (5 months ago)
- Language: PHP
- Size: 10.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://travis-ci.org/kschu91/date-range)
[](https://scrutinizer-ci.com/g/kschu91/date-range/?branch=master)
[](https://scrutinizer-ci.com/g/kschu91/date-range/?branch=master)# PHP Date Range
A small PHP library to extract date ranges out of a list of dates.
## Installation
```bash
composer require "kschu91/date-range"
```If you are not familiar with composer:
[composer basic usage](https://getcomposer.org/doc/01-basic-usage.md)### Requirements
- PHP >= 7.1## Basic Usage
```php
$datePeriods = (new DateRangeInterval(new \DateInterval('P1D'), $dates))->getDatePeriods();
```
### Example
```php
$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
```