How to find Expiry - 1 date

Can anyone please tell me how to check Expiry - 1 trade date? e.g. Suppose weekly expiry date of bank nifty is on 28-Jul i.e. Thr. And if there is a holiday on 27-Jul i.e. Wednesday then when I ask for Expiry date - 1 then should get 26-Jul

Can anyone please tell me how to write this kind of condition? which will handle holidays and return an appropriate trading date.