Sameen Javid Sameen Javid - 1 year ago 77
Javascript Question

check current date is which day of month(Finding which day of month?) in javascript

check that what day of month my current date is, will this solution work in that case as well? Like today 11/21/2016 is Third Monday of month.

Answer Source


 var date = new Date();
 var firstDay = new Date(date.getFullYear(), date.getMonth(), 1);
 var days = ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];
 var weeksPassed = Math.floor(date.getDate()/7); 
 if(date.getDay() >= firstDay.getDay()){
   alert((weeksPassed+1) + " " + days[date.getDay()] + " of month" )
   alert((weeksPassed) + " "+ days[date.getDay()] + " of month" )

explanation :

Date will give you the date of month so by that you can find how many weeks have passed Day will give you day 0 to 6 sun to sat so then if your current day is before the start month of day then current day is no of weeks passed day else its weeks passed + 1 day

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download