Hello, I have the following scenario: I have a year, e.g. 2018, and would now like to calculate the decade, or the year numbers of this decade, from this data. 12 values should always be returned. For the example the years 2009-2020 should be output in an array. How can I implement this? Later I want to do the same in hundreds of steps. (e.g. 1900-3000).

- Take current year, attempt to divide by 10.
- If not an integer, then add 1 to the year. Repeat until integer.
- If integer, then that year is value “Top”. Subtract 11. That year is "Bottom.
- For I = bottom to top, append I to Years().

Surely, there are better and more sophisticated ways. It just works.

For centuries, use a division by 100. It will take slightly longer to start, 50 iterations on average.

decade_begin = floor(year / 10) * 10

since when are there 12 years in a decade… 2018 is in the decade beginning 2011 and ending 2020

While that is technically true of the gregorian calendar, popular culture view a decade as xxx0 - xxx9, such as the 80’s, which were 1980 - 1989. The OP should define what he means by the term “decade”.

either way … a decade is 10 years, not 12

Thanks to all of you. Works pretty good ??