...I'm trying to understand the logic of

$buday = @MDAYNO" - "1"

If you are trying to roll the number back 1 day, then it is flawed. Hell, it's flawed anyway. If doing math, don't put quotes around it. The flaw part is if @MDAYNO = 1 - 1 then it's 0.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.