Reputation: 39
Given any date, how do I find the first month and year in the future where the 31st of that month falls on a Wednesday, in other words, for today, 11 November 2020, I would like to see (31) March 2021. [Updated: Returned month should be March 2021]
Upvotes: 0
Views: 87
Reputation: 53136
If you have Excel 365 then
=LET(DayInMonth, DATE(YEAR($A$2),MONTH($A$2)+SEQUENCE(336,,0,1),$B$2),
DOW, WEEKDAY(DayInMonth),
IsMatch, (DAY(DayInMonth)=$B$2)*(DOW=$C$2)*(DayInMonth>=$A$2),
XLOOKUP(1,IsMatch,DayInMonth,,0,1))
How it works:
A2
is the start date (could be formula =TODAY()
)
B2
is the day number in the month
C2
is the day of week code (1..7 = Sunday..Saturday)1
if calculated DayInMonth matches specified DayInMonth (this excluded non-existant dates) AND Calculated DOW matches specified DOW AND calculated date is on or after start dateXLOOKUP
returns the date of the first 1
in the IsMatch arrayUpvotes: 0
Reputation: 394
@prino,
You could make use of Excel's Iterative Calculation, setting Maximum Iterations
to 1000
.
In the example below, A1
is the given date and B1
receives the result (put the formula in B1
):
=IF(B1=0,A1)+B1+IF(AND(WEEKDAY(B1,1)=4,DAY(B1)=31),0,1)
Upvotes: 0