Just sharing a function I made to calculate the number of work hours in a month.
It takes the input of a MONTH string (1 to 12) and does the rest based on the current year.
- MONTHS={"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
- this_MONTH=MONTHS.get((input.MONTH.toLong() - 1));
- DATE_STRING="01-" + this_MONTH + "-" + (zoho.currentdate.getYear());
- DATE1=DATE_STRING.toDate();
- DATE2=DATE1.addMonth(1);
- DAYS=((DATE2 - DATE1) / 86400000);
- HOURS_LIST={1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32};
- WORK_HOURS=0;
- for each day in HOURS_LIST
- {
- if((day.toLong() <= DAYS))
- {
- DATE_STRING=day + "-" + this_MONTH + "-" + (zoho.currentdate.getYear());
- DATE3=DATE_STRING.toDate();
- WORK_HOURS=if((((day <= DAYS) && (DATE3.getDayOfWeek() > 1)) && (DATE3.getDayOfWeek() < 7)),(WORK_HOURS + 8),WORK_HOURS);
- }
- }
- alert WORK_HOURS;
If you have any questions, let me know.
John M. Whitney