Google Sheets – Calculating Due Date for a Bill

google sheets

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?

Best Answer

When you enter days in column B, there should be also some indication of what month these refer to. Without this information, meaningful date comparisons are impossible.

Let's suppose you put the relevant month, like "12" for December, in B1. Then the formula

=date(year(today()), $B$1, $B22)

returns the date with the month as in B1, day as in B22, and the current year. But considering that one should also prepare for bills that are due next year, it may be better to have a "year" cell too: say, B2 has the year in which these bills are due.

=date($B$2, $B$1, $B22)

You can use this expression in formulas for comparisons with other dates:

=if(AND(D$1 > date($B$2, $B$1, $B22), E$1-1 <= date($B$2, $B$1, $B22)), $C22, "")

This is more effective and reliable than trying to compare DAY(), MONTH() and YEAR() parts in nested If statements.