> For the complete documentation index, see [llms.txt](https://jscula.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jscula.gitbook.io/docs/utils/getyears.md).

# getYears

This function returns an array of years within a specified range, inclusive of the start and end dates.

**Parameters**

* `startDate` (optional, default: 1850): The starting year.
* `endDate` (optional, default: Current year): The ending year.

**Returns**

* An array of numbers representing the years between the specified start and end dates.

**Throws**

* An error is thrown if the end date is less than the start date.

### Without any param will start from 1850 till the current year

```javascript
getYears()// [1850,1851,1852,1853,1854,1855,1856,...2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021,2022,2023,2024]
```

### With param

this will return the years from the given till the current year

```javascript
getYears(2016) // [2016,2017,2018,2019,2020,2021,2022,2023,2024]
```

```javascript
getYears(2019,2023); //[2019,2020,2021,2022,2023]
```
