In this article, I want to help you get the first day of next month in JavaScript by two methods: creating Date() constructor and a conditional sentence. Follow this article in detail to see how I do it.
Get the first day of next month in JavaScript
Using the Date() constructor
If you want to get the first day of the next month, we must get the current time. From the current month, we will add one to get the next month; by default, the first day of the month will be 1
.
Code sample:
// Set the first day of the next month for the new variable function getNextMonth(currentDate){ let nextMonth = new Date(currentDate.getFullYear(), currentDate.getMonth() + 1, 1); console.log(nextMonth); } let now1 = new Date(2022, 12, 10); getNextMonth(now1); let now2 = new Date('November 28 2022'); getNextMonth(now2);
Output
Wed Feb 01 2023 00:00:00 GMT+0700 (Indochina Time)
Thu Dec 01 2022 00:00:00 GMT+0700 (Indochina Time)
The first example shows that the current month is December, so the Date() constructor will automatically update the next month as January of the new year. In the second example, the current month is November, so the first day of the next month is December 1, 2022.
Using the Date() constructor and the statement
You can also use conditional statements to check the current month. It has to be changed to the new year if it’s December. Otherwise, it only takes one more month to become the next month.
Code sample:
// If the current month is December, set January to the new year function getNextMonth(currentDate){ if(currentDate.getMonth() == 11){ let nextMonth = new Date(currentDate.getFullYear() + 1, 0, 1); console.log(nextMonth); } else { let nextMonth = new Date(currentDate.getFullYear(), currentDate.getMonth() + 1, 1); console.log(nextMonth); } } let now1 = new Date(2022, 12, 3); getNextMonth(now1); let now2 = new Date('November 28 2022'); getNextMonth(now2);
Output
Wed Feb 01 2023 00:00:00 GMT+0700 (Indochina Time)
Thu Dec 01 2022 00:00:00 GMT+0700 (Indochina Time)
Note that in Javascript, the getMonth() method will return the month of the specific date in Local Time. The function returns an integer from 0 to 11. So 0 is January, 11 is December.
Summary
In conclusion, to get the first day of next month in JavaScript, you need to set the default date parameter to 1 and increment one month for the date parameter, and the year will still take the current year. Finally, pass all 3
parameters to the Date() constructor and you will get the correct result. Practice and see the results. Thank you for reading, and see you in the next post.
Maybe you are interested:
- Get the Number of Years between 2 Dates in JavaScript
- Get the Hours and Minutes from a Date in JavaScript
- Get the first Day of the current Week using JavaScript

Hi, my name is Joni Smith. My job is a programmer. I love learning programming languages, especially C++, C#, php, javascript, html, css. I want to share them with you. I hope my articles will bring a lot of useful knowledge to you.
Name of the university: HVNH BA
Major: htttql MIS
Programming Languages: C++, C#, php, javascript, html, css