Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a function to compute the number of business days between two dates #84

Closed
MrPowers opened this issue Mar 14, 2023 · 4 comments
Closed

Comments

@MrPowers
Copy link
Collaborator

See this comment and some of the other comments that follow.

The function should be in functions.py and be called something like business_days_between or something (consistent with this this answer).

@fpvmorais
Copy link
Contributor

fpvmorais commented Mar 15, 2023

Here's a possible solution to calculate:

CREATE FUNCTION IF NOT EXISTS udf_workdays(StartDate date,
                                           EndDate date,
                                           Holidays array<date> array())
RETURNS int
RETURN
(
    REDUCE(
      ARRAY_EXCEPT(SEQUENCE(StartDate, EndDate),Holidays)
      0,
      (acc, x) -> acc + IF(DATE_FORMAT(x, 'E') IN ('Sat', 'Sun'), 0, 1))
);

This UDF can accept an optional list of holidays to exclude besides the weekend days

@robertkossendey
Copy link

Thank you for the contribution! But I think we should make it work without an UDF, so that Spark can optimize the query

@puneetsharma04
Copy link
Contributor

@MrPowers : I would like to work on this issue , can you assign this issue to me?

@MrPowers
Copy link
Collaborator Author

MrPowers commented Oct 8, 2023

This was added!

@MrPowers MrPowers closed this as completed Oct 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants