Forum Discussion

JenniferSilbers's avatar
JenniferSilbers
Qrew Trainee
4 years ago

Total work days in a Month

Hello,

I am trying to calculate the total work days in a month based on today's date.  Here is my formula but it is not working correctly, I am getting a total of 25 days for February and there are only 20 working days in February for this year.  Dates and duration formulas in Quick Base are new for me so any help is appreciated. 

Formula:
ToDays(ToWeekdayP(LastDayOfMonth([Today's Date])) - (ToWeekdayN(FirstDayOfMonth([Today's Date]))))

My team wants to see what business day they are on (which I figured out) and then how many business days are in each month.  

Thanks

------------------------------
Jennifer Silberstein
------------------------------

2 Replies

  • Hi Jennifer,

    Please try this out. I tested it on each month of 2021, and it looks good to me.

    [Input Date] is another field, however you can replace this with any Date value.

    var date firstDay = ToWeekdayN(FirstDayOfMonth([Input Date]));
    var date lastDay = ToWeekdayP(LastDayOfMonth([Input Date]));
    var number daysInMonth = ToDays($lastDay - $firstDay) +1;
    var number lastDayName = DayOfWeek($lastDay);
    var number lastWeekendOffset = If ( $lastDayName = 0, 2, $lastDayName = 6, 1, 0);
    var number weekends = Floor($daysInMonth / 7);
    var number weekendDays = ($weekends * 2);

    $daysInMonth - $weekendDays



    ------------------------------
    Gary Blasco
    ------------------------------
    • JenniferSilbers's avatar
      JenniferSilbers
      Qrew Trainee

      Hi Gary,

      Thank you for the help.  I will give this a try, I already see uses for individual pieces in the formula for other formulas I have been trying to do. 

      Have a great day!



      ------------------------------
      Jennifer Silberstein
      ------------------------------