Click here to Skip to main content
15,881,281 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Hi,
how to write working days in month code in javascript?
please solve my problem plzzzzzzzzzzzzzz.
Posted
Updated 13-Nov-11 19:48pm
v2
Comments
Prerak Patel 14-Nov-11 1:08am    
Not clear. Elaborate. Do you want count or dates?!
Hari Krishna Prasad Inakoti 14-Nov-11 1:20am    
count only

You can't accurately, without a lot of external information.

To calculate the basic working days count (without holidays, and assuming Monday to Friday only):
Java
function getDaysInMonth(iMonth, iYear)
    {
    return 32 - new Date(iYear, iMonth, 32).getDate();
    }

function isWorkDay(year, month, day) 
    {
    var dayOfWeek = new Date(year, month, day).getDay();
    return dayOfWeek >=1 && day <=5; // Sun = 0, Mon = 1, and so forth
    }

function getWorkDays(month, year)
    {
    var days = getDaysInMonth(month, year);
    var workdays = 0;
    for(var i = 0; i < days; i++) 
        {
        if (isWorkDay(year, month, i+1)) 
            {
            workdays++;
            }
        }
    return workdays;
    }

The problem is that that does not give you an accurate count - you also need to allow for holidays, and working those out is a lot harder, and will vary from region to region.
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900