Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
8
rated 0 times [  13] [ 5]  / answers: 1 / hits: 19274  / 11 Years ago, fri, january 3, 2014, 12:00:00

If a date is given (for example-2014-01-07) ,I want to access that specific month (January 2014) and get the date number of the Saturdays and Sundays of that month.



In this case,
4,11,18,25 --Saturdays
5,12,19,26 -- Sundays



I want to use java script because this is a front end development.
Help me out with this..Thnkz


More From » jquery

 Answers
10

Try with this FIDDLE



var d = new Date();
var getTot = daysInMonth(d.getMonth(),d.getFullYear()); //Get total days in a month
var sat = new Array(); //Declaring array for inserting Saturdays
var sun = new Array(); //Declaring array for inserting Sundays

for(var i=1;i<=getTot;i++){ //looping through days in month
var newDate = new Date(d.getFullYear(),d.getMonth(),i)
if(newDate.getDay()==0){ //if Sunday
sun.push(i);
}
if(newDate.getDay()==6){ //if Saturday
sat.push(i);
}

}
console.log(sat);
console.log(sun);


function daysInMonth(month,year) {
return new Date(year, month, 0).getDate();
}


In sat and sun Array() you can get the Saturdays and Sundays of particular month


[#73405] Thursday, January 2, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mckenna

Total Points: 445
Total Questions: 109
Total Answers: 109

Location: Virgin Islands (U.S.)
Member since Sun, May 16, 2021
3 Years ago
;