I use Google Sheets to track our household financial budget. I've been slowly refining the functionality over the years, but have arrived at a point where I can't figure out how to achieve the next goal.

Across the top of the sheet (row 1), starting in column D, I have dates spaced out every two weeks (the schedule on which I get paid). Down the columns I have listed values for whatever needs to get paid out of that paycheck (rent, electric bill, student loan payment, etc.). What I want to do is, for each row in column B, put a value (1-31) for the day of the month that the bill is due on. If that value falls between the day I get paid and the day before the next time I get paid (e.g. DAY(D$1) and DAY(E$1)-1), I want to list the value in column C.

What I've come up with so far is this:
`=if(AND(DAY(D$1)>$B22,DAY(E$1)-1<=$B22),$C22,"")`

It doesn't work. How can I make it do what I want?