#T-SQL, 296 bytes
T-SQL, 296 bytes
#T-SQL, 296 bytes
T-SQL, 296 bytes
#T-SQL, 296 bytes
Created as a table valued function
create function d(@ char(5))returns table return select min(o)o from(select datediff(day,cast('2016'+right(@,2)+left(@,2)as date),cast(right('2016'+right('0'+cast(d as varchar(4)),4),8)as datetime)+1)o from(values(324),(325),(327),(424),(501),(1002),(1224),(1225),(1226),(1231))d(d))d where 0<=o
Used in the following manner
SELECT *
FROM (
VALUES
('01/05') --= 1
,('02/05') --= 0
,('03/05') --= 153
,('25/12') --= 0
,('26/12') --= 0
,('27/12') --= 0
,('30/12') --= 2
,('31/12') --= 1
)testData(i)
CROSS APPLY (
SELECT * FROM d(t)
) out
i o
----- -----------
01/05 1
02/05 0
03/05 153
25/12 0
26/12 0
27/12 0
30/12 2
31/12 1
(8 row(s) affected)
A brief explanation
create function d(@ char(5)) returns table -- function definition
return
select min(o)o -- minimum set value
from(
select datediff( -- date difference
day, -- day units
cast('2016'+right(@,2)+left(@,2)as date), -- convert input parameter to date
cast(right('2016'+right('0'+cast(d as varchar(4)),4),8)as datetime)+1 -- convert int values into datetimes and add a day
)o
from(
values(324),(325),(327),(424),(501),(1002),(1224),(1225),(1226),(1231) -- integers representing the day before public holidays
)d(d)
)d
where 0<=o -- only for values >= 0