Skip to content
Advertisement

Firebird calc between date skip weekend

I want to convert this sql code to firebird sql for find working days between two dates:

thanks

Advertisement

Answer

Your current SQL Server function is a table-valued function (it returns a table), the closest equivalent in Firebird 3 (and earlier) would be a selectable stored procedure:

The normalization of the to and from dates to Sunday for the week difference is necessary, as unfortunately for datediff(week ...) Firebird doesn’t count the weeks, but periods of 7 days between two dates, so for example datediff(week, date'2017-07-14', date'2017-07-20') (a Friday to the next Thursday) is 0, not 1. Normalizing to the Sunday of the week will ensure that the week difference is calculated correctly.

One word of warning: I have only tested this with a (small) selection of dates and compared it to the output of the SQL Server function, and I have not tested with a time component, you might want to verify it more thoroughly.

Given the nature of the data, you could also have used a scalar function in SQL Server. The equivalent of a scalar function would be a PSQL function (which was introduced in Firebird 3)

References:

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