Skip to main content
2 of 5
add note regarding Microsoft Excel compatibility
doubleunary
  • 2.7k
  • 1
  • 2
  • 12

Google Sheets / Microsoft Excel, 78 bytes

=let(d,workday(eomonth(A1,0)+1,-1),text(d,"dddd dd")&if(day(d)=31,"st","th"))

Put the month and year in one of the formats specified in the question, or any other valid date, in cell A1, and the formula in B1.

The formula gets the first day of the next month and then finds the previous weekday before that, which is the same as the last weekday of the specified month.

The day number of the last weekday of a month will never end in 2 or 3, so it is enough to add st when the day is 31 and use th with any other date.

The Google Sheets epoch is 30 December 1899 and the formula will only work with dates from January 1900 on.

Tested the formula in the most recent version of Microsoft Excel for the web and seems to work the same there.

input expected formula
10/2023 Tuesday 31st Tuesday 31st
February 2017 Tuesday 28th Tuesday 28th
09/1674 Friday 28th #NUM!
1/2043 Friday 30th Friday 30th
doubleunary
  • 2.7k
  • 1
  • 2
  • 12