Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,894 questions

51,825 answers

573 users

How to get all dates in specific month with Node.js

1 Answer

0 votes
function getAllDaysInMonth(year, month) {
  	const date = new Date(year, month, 1);

  	const dates = [];

  	while (date.getMonth() === month) {
    	   dates.push(new Date(date));
    	   date.setDate(date.getDate() + 1);
  	}

  	return dates;
}


const date = new Date('2022-06-01');

const dates = getAllDaysInMonth(date.getFullYear(), date.getMonth());
 
for (let i = 0; i < dates.length; i++) {
     console.log(dates[i].toDateString());
}

 
 
 
 
/*
run:
 
Wed Jun 01 2022
Thu Jun 02 2022
Fri Jun 03 2022
Sat Jun 04 2022
Sun Jun 05 2022
Mon Jun 06 2022
Tue Jun 07 2022
Wed Jun 08 2022
Thu Jun 09 2022
Fri Jun 10 2022
Sat Jun 11 2022
Sun Jun 12 2022
Mon Jun 13 2022
Tue Jun 14 2022
Wed Jun 15 2022
Thu Jun 16 2022
Fri Jun 17 2022
Sat Jun 18 2022
Sun Jun 19 2022
Mon Jun 20 2022
Tue Jun 21 2022
Wed Jun 22 2022
Thu Jun 23 2022
Fri Jun 24 2022
Sat Jun 25 2022
Sun Jun 26 2022
Mon Jun 27 2022
Tue Jun 28 2022
Wed Jun 29 2022
Thu Jun 30 2022
 
*/

 



answered Apr 1, 2022 by avibootz

Related questions

2 answers 136 views
1 answer 108 views
1 answer 95 views
1 answer 97 views
1 answer 97 views
...