Calculate Next Business Date Excluding Weekends & Holidays In Salesforce LWC

Hey folks, today in this post we are going to learn that how we can calculate and auto populate next working business day/date in salesforce lighting web component using javaScript. we will calculate and find out further business date excluding weekends and public holidays.

business date calculation LWC

Step 1 : Create a Lightning Web Component

  1. In Visual Studio Code, open the Command Palette by pressing Ctrl+Shift+P (Windows) or Cmd+Shift+P (macOS).
  2. Type sfdx and Select SFDX: Create Lightning Web Component.
  3. Enter businessDateCalculator for the name of the new component and Press Enter.

Copy and paste the following code and save the file.


  • In html file we have a lightning input(date type) base tag.

  • Line 5-10 : First we have define our list of holidays dates which we need to exclude. you can add more items in this list.
  • Next on component initialize function (connectedCallback), we are calculating next working business date (from today’s date).
  • isHoliday  : Function to check whether current date is in holidays list or not.
  • compare : Function to compare 2 dates. if both dates are equal then return true otherwise return false.
  • Tip : You can make it more flexible by storing holidays data in custom metadata.
  • Check code comments.

Deploy LWC Folder To Org :

  1. Right-click the businessDateCalculator folder.
  2. Click SFDX: Deploy Source to Org.

Output : 

  • Add your LWC to lightning home page from app builder to see the output.

business date calculation LWC

Other popular Post :

Follow us for new post updates. & Don’t forget to bookmark this site for your future reference.

Facebook :

Instagram :

Buy me a coffeeBuy me a coffee

(Visited 671 times, 1 visits today)

Leave a Comment