Skip to content
Advertisement

Counting Business Days PostgresSQL

I am attempting to do something like this:

Where “Foo” is some sql mumbo-jumbo to calculate the business days between startdate and enddate like such:

I was able to create a function to do so with no trouble:

Is there anyway I can achieve this without having to use this function?

Bonus Question for Bonus Points:

Would it be possible to allow for a timestamp to be entered and just have it cast to date within the actual function? I’m just curious.

Advertisement

Answer

You can replace the function with a lateral join:

I am unsure about your question regarding the timestamp/date casting. If your columns have a time component and you don’t want to take it into account, then you can cast in generate_series():

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement