Pull date range excluding holidays/weekends

  • Goal:
    Pull monthly day totals excluding holidays and weekends. Ex: July 2024, this would show 22 days since there were 4 weekends and 1 holiday (4th of July)

  • Steps: The data would be visualized on a page element like in the screenshot.
    Screenshot 2024-07-22 at 3.24.00 PM

I've tried to create a variable using Moment.js or other libraries but I get an error indicating you "Cannot use import statement outside a module".

Hi @adrquint! Thanks for posting. :slight_smile:

There does seem to be a nice extension to moment that would do the trick here but it doesn't seem to be compatible with our "Libraries" feature, for whatever reason. For reference, you can load in external libraries via the "App Settings -> Libraries" menu. This bypasses the need to write require or import statements.

You might notice that I added a library called date-holidays, though, which we can use in conjunction with moment to solve your problem.

The above query I wrote is spitting out 22, which aligns with what we would expect to see for August! We can then connect the data source for some component on our page to the output of this query.

Definitely let us know if you have any questions about the logic or syntax here - everybody has varying levels of experience writing JS scripts.