Get all of the dates between two given dates
npm install dates-betweenGet all of the dates between two given dates, with generators.
``js
const startDate = new Date('2016-01-01');
const endDate = new Date('2017-01-01');
for (const date of datesBetween(startDate, endDate)) {
console.log(date);
}
`
* Requirements
* Usage
* Migration
* Contributing
* License
This library requires the following to run:
* Node.js 20+
Install with npm:
`sh`
npm install dates-between
Load the library into your code with a require call:
`js`
const { datesBetween } = require('dates-between');
The datesBetween function accepts two arguments, a start date and an end date. Both of these must be Date objects:
`js`
datesBetween(new Date('2016-01-01'), new Date('2016-02-01'));
This returns an iterable which can be iterated over in a for..of construct. The yielded dates include both the start and end date that were passed in.
`js`
for (const date of datesBetween(startDate, endDate)) {
console.log(date);
}
Because datesBetween returns an iterable, you can also create a Set or Array from it:
`js`
const dates = new Set(datesBetween(startDate, endDate));
`js`
const dates = Array.from(datesBetween(startDate, endDate));
Usage examples can be found in the example` directory of this repository.
A new major version of this project is released if breaking changes are introduced. We maintain a migration guide to help users migrate between these versions.
The contributing guide is available here. All contributors must follow this library's code of conduct.
Licensed under the MIT license.
Copyright © 2016, Rowan Manning