Tip 6: How to calculate the business days between two dates.

Tip 6: How to calculate the business days between two dates.



Hi everyone,


Following our Zoho Creator - Tips and Tricks series every fortnight, we are back today with a tip based on one of the most asked questions in the forum. That's right. This tip would help you calculate the business days between two dates excluding the weekend.

For example, if wish to know the number of working days in a particular month, you need to write a custom function to do this calculation.

Functions are nothing but a unit of code written to perform a specific task.


Let's see how to do this:


  1. // Here WorkDays is the name of the function.
  2. int WorkDays(date start_date, date end_date)
  3. {
  4. //total_days will store the value of numbers of days between start date and end date.
  5. total_days=(days360(input.start_date,input.end_date) +1);
  6. counter=leftpad("1",total_days).replaceAll(" ","1,").toList();
  7. //Here counter will generate a list like {1,1,1,1,1,1} with number of 1's based on value returned in total_days.
  8. week_ends=0;
  9. date_counter=input.start_date;
  10. for each index n in counter
  11. {
  12. //Use getDayOfWeek() to identify if it is a weekday or weekend. 
  13. if((date_counter.getDayOfWeek() == 1) || (date_counter.getDayOfWeek() == 7))
  14. {
  15. week_ends=(week_ends + 1);
  16. }
  17. //Now add one day for the next loop
  18.  date_counter=date_counter.addDay(1);}
  19. total_business_days=(total_days - week_ends);
  20. return total_business_days;
  21. }

 

Let's look at some of the built-in functions that we used in the above code:

days360 is a built-in function that returns the number of days between two given dates.


getDayOfWeek is a built-in function to get the day of the week corresponding to a date. It will return a number range from 1 to 7. The number 1 represents a Sunday, 2 represents a Monday and so on.

replaceAll is a built-in function that helps you replace all the occurrence of a particular substring in a sting.


toList is a built-in function that removes the given separator in a string, and replaces it with a comma.

Isn't it easy? Give it a try. If you have any doubts or queries regarding this tip, please feel free to add them as comments below. We would be happy to address them all.




    Access your files securely from anywhere

          Zoho Developer Community




                                    Zoho Desk Resources

                                    • Desk Community Learning Series


                                    • Digest


                                    • Functions


                                    • Meetups


                                    • Kbase


                                    • Resources


                                    • Glossary


                                    • Desk Marketplace


                                    • MVP Corner


                                    • Word of the Day



                                        Zoho Marketing Automation


                                                Manage your brands on social media



                                                      Zoho TeamInbox Resources

                                                        Zoho DataPrep Resources



                                                          Zoho CRM Plus Resources

                                                            Zoho Books Resources


                                                              Zoho Subscriptions Resources

                                                                Zoho Projects Resources


                                                                  Zoho Sprints Resources


                                                                    Qntrl Resources


                                                                      Zoho Creator Resources



                                                                          Zoho Campaigns Resources


                                                                            Zoho CRM Resources

                                                                            • CRM Community Learning Series

                                                                              CRM Community Learning Series


                                                                            • Kaizen

                                                                              Kaizen

                                                                            • Functions

                                                                              Functions

                                                                            • Meetups

                                                                              Meetups

                                                                            • Kbase

                                                                              Kbase

                                                                            • Resources

                                                                              Resources

                                                                            • Digest

                                                                              Digest

                                                                            • CRM Marketplace

                                                                              CRM Marketplace

                                                                            • MVP Corner

                                                                              MVP Corner





                                                                                Design. Discuss. Deliver.

                                                                                Create visually engaging stories with Zoho Show.

                                                                                Get Started Now


                                                                                  Zoho Show Resources


                                                                                    Zoho Writer Writer

                                                                                    Get Started. Write Away!

                                                                                    Writer is a powerful online word processor, designed for collaborative work.

                                                                                      Zoho CRM コンテンツ






                                                                                        Nederlandse Hulpbronnen


                                                                                            ご検討中の方





                                                                                                  • Recent Topics

                                                                                                  • Remove or hide default views

                                                                                                    I'm looking to only have the views pertinent to my organization.  Is there a way to show only my custom views (or separate them to a different area or something)? If not, this should be a feature as switching from Zendesk we had this option...
                                                                                                  • Analytics Module: Can you move items from one dashboard to another?

                                                                                                    Is there a way to move items from one dashboard to another? I want to rearrange my dashboard now that I know what i'm doing but i don't want to remake my various widgets? Edit: Hey Zoho, This would be a good feature: to be able to move/copy widgets to
                                                                                                  • Copy Widget to another Dashboard

                                                                                                    I can see the option to clone a widget to the same dashboard but is it possible to copy it to another dashboard?
                                                                                                  • Is there a way to print the dashboard?

                                                                                                    I would like the capability of printing the dashboard - is that possible?
                                                                                                  • Custom Deal Name in Lead Conversion Mapping

                                                                                                    I know there are ways to change the name of a Deal after conversion using a custom function, so no need to repost that information. I would like to see the CRM Improved with Deal Name Customisation and I think the Lead Conversion Mapping page would be
                                                                                                  • Build custom AI solutions with Catalyst’s QuickML capabilities in CRM

                                                                                                    Hello everyone, We’re thrilled to announce an improvement for our Zoho CRM Enterprise users: the ability to create custom AI solutions using Catalyst’s QuickML directly from Zoho CRM. As you may already know, Zia, Zoho CRM’s AI-powered assistant, offers
                                                                                                  • Recommendations to store meeting notes for easy access from Contacts, Accounts & Deals module records?

                                                                                                    I would like your advice on how to achieve this use case for my organization. It’s related to where/how best to store meeting notes from a conversation with Contact(s) working at an Account (Company) in the context of a Deal. The ideal solution (from
                                                                                                  • Introducing Record Summary: smarter insights at your fingertips

                                                                                                    Hello everyone, Building on the recent launch of Zoho's in-house Zia Large Language Model (Zia LLM)—a major milestone in Zoho CRM’s AI capabilities—we’re excited to introduce the Record Summary feature. This powerful addition makes use of Zia LLM to simplify
                                                                                                  • Suppress "spreadsheet will not be saved" message on published sheet

                                                                                                    I have published a sheet and have one column on that sheet that the user can edit (a dropdown picklist where the user can select the status for each line). Is there a way to suppress the Zoho Sheet message "Any changes made to this published spreadsheet
                                                                                                  • Missing "Email Authentication" tab

                                                                                                    Backstage is alerting users about "Unauthenticated Domains" with a large prompt in the backend. It adds a link to learn more. On this tutorial page, it shows where to find the "Email Authentication" tab in this screenshot. However, in our Backstage, that
                                                                                                  • Blueprint - 'On hold' state with an automatic transition?

                                                                                                    I think I'm missing something here so I'm hoping if I explain what I'm trying to achieve someone might be able to give me a way around it. We sometimes get request far in advance but we don't want to action them unless it is 7 days from when they are
                                                                                                  • Show item Cost value on Item screen

                                                                                                    The Item screen shows Accounting Stock and Physical Stock. It would be very helpful if value information could be displayed here as well, for instance Cost Price. Currently, to find the Cost Price (as used for inventory valuations) from inside the item
                                                                                                  • Feature Request: Search in the PC client. Some thoughts about the search.

                                                                                                    Hi all. I'm really excited to start using Zoho Notebook, but I'm missing some of the search capabilities on my desktop. There are also some thoughts on improving search in general. Search is very important to me, without it it is difficult for me to use
                                                                                                  • Gravity Forms plugin not passing some fields

                                                                                                    I use the gravity form zoho plugin to push data from my lead form into my lead page in Zoho CRM. Everything was working file for about 6 months. Suddenly on Oct 1st, some of the fields are no longer getting passed to Zoho. The fields with the problem
                                                                                                  • Zoho Analytics to Zoho Sheets - automatic update?

                                                                                                    Hi all, If I create a zoho sheet from an Analytics Report or Analytics Data, is there a way for the zoho sheet to automatically update as the Report / Data in analytics updates?
                                                                                                  • Phone App of CRM doesn't find contacts

                                                                                                    I open the crm to and do a contact search but nothing comes up. If I do a full zia search it will find an old note that is attached to a contact and I can open the contact. BUT I still can't enter notes of calls, set appointments, etc. It requests I go
                                                                                                  • Integration with Moodle

                                                                                                    Greetings, I hope find all doing well and safe. I've recently returned to using Zoho Flow after a break and was hoping to connect my WooCommerce store with Moodle, the world's most widely used learning management system. My goal was to automatically enroll
                                                                                                  • Task status - completed - other options

                                                                                                    I have a dumb question I know i can make custom statuses for the tasks - but is there anyway to make additional "completed" statuses like for instance if i have a task "call back customer" and i leave a vm for them to call back marking it "completed -
                                                                                                  • Task module and related-to field

                                                                                                    In modules other than the Task Module I can add several lookup fields to provide a variety of relationships. In the Task module lookup fields are not available. There is only one "related to" field which I want to use for Company. But I want to relate
                                                                                                  • Zoho Assist "Agree and Download" Button "Greyed Out" ("Light Blued" Out)

                                                                                                    Anyone else having issue where support clients are unable to click "Agree and Download" to access the client so that we can provide remote support? This is for "on demand" support via accessing the support page and entering the support key and name. This
                                                                                                  • Add Lookup Field in Tasks Module

                                                                                                    Hello, I have a need to add a Lookup field in addition to the ones that are already there in the Tasks module. I've seen this thread and so understand that the reason lookup fields may not be part of it is that there are already links to the tables (https://help.zoho.com/portal/en/community/topic/custom-fields-on-task-module).
                                                                                                  • migrating from Zoho Invoices (CRM) to Zoho Books

                                                                                                    Good day, I was wondering if there was a easy way to migrate all the quotes and invoices from Zoho Invoices CRM to Zoho Books. We plan to move to using Zoho Books in a few weeks and would like to have all the quotes and invoices from the past 3 years
                                                                                                  • Zoho MA and Custom Module

                                                                                                    I am trying to create a sync between Markting Automation and Zoho CRM. I am mapping a custom module from the CRM. The custom module has email field mobile phone field However I cannot finish the integration since the system keeps asking me for email or
                                                                                                  • When is partial reimbursement going to be launched?

                                                                                                    Hi there. I saw somewhere that the partial reimbursement feature is in the work. What is the update and ETA of that? Our clients and prospects have been asking us and we agree that that is an important feature to have.
                                                                                                  • All notes disappeared

                                                                                                    I've been using the notebook app for over five years on my phone without being logged into an account. A few days ago I opened the app and all my notes had disappeared. Since then I tried restarting my phone, updating the app and logging into my account,
                                                                                                  • Introducing Keyboard Shortcuts for Zoho CRM

                                                                                                    Dear Customers, We're happy to introduce keyboard shortcuts for Zoho CRM features! Until now, you might have been navigating to modules manually using the mouse, and at times, it could be tedious, especially when you had to search for specific modules
                                                                                                  • Is there any support for Drivers license and other forms of ID scanning capabilities?

                                                                                                    When scanning a drivers license barcode for data input to a Form, the scanning tool receives all the raw data but there doesnt seem to be a function to limit or remove the unnecessary fragmrnts, like a prefix. Is there any support or info in the help
                                                                                                  • Year-End Wrap: Declutter Your Inbox Using Email Filters

                                                                                                    Ping!—an email drops in. And another. And another! It's finally that time of the year when your inbox will be bursting with messages from team members, clients, and marketing agents, leaving you feeling overwhelmed and distracted. Sounds familiar? Now
                                                                                                  • Unified Notes View For Seamless Collaboration

                                                                                                    To facilitate better coordination among different departments and team members, the notes added to a record can now be accessed in all its associated records. With this, team members, from customer service representatives to field technicians, can easily
                                                                                                  • Q4 Europe In-person Zoho User Group Meetup: Streamlining Your Business Processes & Introduction to Zoho CRM for Everyone

                                                                                                    Hello Zoho Community, We are excited to announce our upcoming Zoho User Group meetup in Europe! This session is designed to help you streamline your business processes using Zoho CRM, with a special focus on enhancing customer interactions and leveraging
                                                                                                  • Formula fields - Request for dynamic recalculation / proper implementation

                                                                                                    Hi Guys, I have a big problem with Zoho formula fields. They don't recalculate each time the record is viewed - only when a record is edited. Formula fields should be updated dynamically each time a record is retrieved. As an example: I have a formula
                                                                                                  • Items attribute questions

                                                                                                    Many of my items have attributes, such as size and color. How can I add new fields to the "New Items" screen to capture that in my Purchase Orders, Items, and Sales Order pages? I only see these attribute fields when adding an Item Group. Also, on the
                                                                                                  • What do the Image Sizes mean in Zoho CRM Email Templates?

                                                                                                    Below you can see the image options in email templates: Banner, Fit, Small, Medium, Original, Custom. Can someone from Zoho please share with me: What each is/means? How each will look on desktop AND mobile? How to edit "custom"?  If I choose "Custom"
                                                                                                  • Workflows for Timesheet

                                                                                                    Good day, Any way to have timesheet as triggers? I looked into Zoho Flow and into Zoho Project automation but no where can I have timesheet as a trigger. Basically, I would like to trigger something upon timesheet approval. Right now, the only way to
                                                                                                  • Organize and Track Phases with Phase Custom Views

                                                                                                    Phase Custom Views let you filter and display phases based on specific criteria. This helps you focus on what’s most relevant for you and your team. Filter phases using criteria such as budget, status, and more. Share views with specific users or teams
                                                                                                  • Record Asset Received as Payment

                                                                                                    How exactly would you account for this in books? For example, I receive a mini computer for a review and I get to keep it after the video is published. Would debit my normal asset account (e.g. Computers) and credit an income account (e.g. Other Income).
                                                                                                  • Transform Your Customer Support with AI-Powered Chatbots in Zoho SalesIQ

                                                                                                    Ever wondered how some companies seem to have superhuman customer support? Let's uncover their secret! In the digital age, customer expectations are skyrocketing. Did you know that according to McKinsey, 75% of consumers expect a response within five
                                                                                                  • Unused items should not count into the available number of custom fields

                                                                                                    Hey, I realized that unused Items reduce the number of available custom fields. I can't see a case where that makes sense. Especially in our case where we have two different layouts in Deals with a lot of different fields, this causes problems.
                                                                                                  • Power of Automation :: Automatically start / pause / stop timer on task status update.

                                                                                                    Hello Everyone, A Custom function is a user-written set of code to achieve a specific requirement. Set the required conditions needed as when to trigger using the Workflow rules (be it Tasks / Project) and associate the custom function to it. Requirement:-
                                                                                                  • Progressive Invoicing

                                                                                                    Progressing invoicing is needed for many industries. It would be great to see it implemented into Zoho Books as well. Set up and send progress invoices in QuickBooks Desktop (intuit.com)
                                                                                                  • Next Page