'Google Apps Script not incrementing date correctly after 12/25/2021
This is my first post here, so forgive me if I'm doing this wrong. I am incrementing a year's worth of dates as follows:
for (i = 0; i <= 360; i++){
bDate.setDate(bDate.getDate() + 1);
bArray.push([Utilities.formatDate(bDate, "GMT", "M/dd/YYYY")]);
}
It works just fine until 12/25/2021, at which point Apps Script decides to celebrate New Year's a few days early!!! See below:
[12/22/2021], [12/23/2021], [12/24/2021], [12/25/2021], [12/26/2022], [12/27/2022], [12/28/2022], [12/29/2022], [12/30/2022], [12/31/2022], [1/01/2022], [1/02/2022]
Am I doing something wrong or is this some sort of bug?
Solution 1:[1]
In fact, your error comes from the misusage of the YYYY which should be here yyyy. Y stands for week year and y for year. Please read MisusedWeekYear.
And read with more attention the post question given by @somario where the solution is given at the end.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Gaƫl Roustan |
