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,895 questions

51,826 answers

573 users

How to get all dates in specific month with TypeScript

1 Answer

0 votes
function getAllDaysInMonth(year : number, month : number) {
  	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-05-01');

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

 
 
 
 
/*
run:
 
"Sun May 08 2022" 
"Mon May 09 2022" 
"Tue May 10 2022" 
"Wed May 11 2022" 
"Thu May 12 2022" 
"Fri May 13 2022" 
"Sat May 14 2022" 
"Sun May 15 2022" 
"Mon May 16 2022" 
"Tue May 17 2022" 
"Wed May 18 2022" 
"Thu May 19 2022" 
"Fri May 20 2022" 
"Sat May 21 2022" 
"Sun May 22 2022" 
"Mon May 23 2022" 
"Tue May 24 2022" 
"Wed May 25 2022" 
"Thu May 26 2022" 
"Fri May 27 2022" 
"Sat May 28 2022" 
"Sun May 29 2022" 
"Mon May 30 2022" 
"Tue May 31 2022" 
 
*/

 



answered Apr 1, 2022 by avibootz
...