Skip to main content
added 31 characters in body
Source Link
doubleunary
  • 2.7k
  • 1
  • 2
  • 12

Google Sheets / Microsoft Excel, 76 bytes

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

Put the month and year in cell A1 in one of the formats specified in the question (or any other valid date format), 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.

Tested theThe formula is for Google Sheets, but I tested it in the most recent version of Microsoft Excel for the web and it seems to work the fine there as well.

The Google Sheets epoch is 30 December 1899. The formula will work with dates from January 1900 to December 99999. In Microsoft Excel, the range of valid dates seems more limited, and formula will work from January 1900 to November 9999.

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

Google Sheets / Microsoft Excel, 76 bytes

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

Put the month and year in cell A1 in one of the formats specified in the question (or any other valid date format), 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.

Tested the formula in the most recent version of Microsoft Excel for the web and it seems to work the fine there as well.

The Google Sheets epoch is 30 December 1899. The formula will work with dates from January 1900 to December 99999. In Microsoft Excel, the range of valid dates seems more limited, and formula will work from January 1900 to November 9999.

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

Google Sheets / Microsoft Excel, 76 bytes

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

Put the month and year in cell A1 in one of the formats specified in the question (or any other valid date format), 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 formula is for Google Sheets, but I tested it in the most recent version of Microsoft Excel for the web and it seems to work the fine there as well.

The Google Sheets epoch is 30 December 1899. The formula will work with dates from January 1900 to December 99999. In Microsoft Excel, the range of valid dates seems more limited, and formula will work from January 1900 to November 9999.

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
deleted 1 character in body
Source Link
doubleunary
  • 2.7k
  • 1
  • 2
  • 12

Google Sheets / Microsoft Excel, 7776 bytes

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

Put the month and year in cell A1 in one of the formats specified in the question (or any other valid date format), 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.

Tested the formula in the most recent version of Microsoft Excel for the web and it seems to work the fine there as well.

The Google Sheets epoch is 30 December 1899. The formula will work with dates from January 1900 to December 99999. In Microsoft Excel, the range of valid dates isseems more limited, and formula will work from January 1900 to November 9999.

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

Google Sheets / Microsoft Excel, 77 bytes

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

Put the month and year in cell A1 in one of the formats specified in the question (or any other valid date format), 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.

Tested the formula in the most recent version of Microsoft Excel for the web and it seems to work the fine there as well.

The Google Sheets epoch is 30 December 1899. The formula will work with dates from January 1900 to December 99999. In Microsoft Excel, the range of valid dates is more limited, and formula will work from January 1900 to November 9999.

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

Google Sheets / Microsoft Excel, 76 bytes

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

Put the month and year in cell A1 in one of the formats specified in the question (or any other valid date format), 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.

Tested the formula in the most recent version of Microsoft Excel for the web and it seems to work the fine there as well.

The Google Sheets epoch is 30 December 1899. The formula will work with dates from January 1900 to December 99999. In Microsoft Excel, the range of valid dates seems more limited, and formula will work from January 1900 to November 9999.

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
add more detailed notes regarding valid date ranges and Excel
Source Link
doubleunary
  • 2.7k
  • 1
  • 2
  • 12

Google Sheets / Microsoft Excel, 7877 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 cell A1 in one of the formats specified in the question, or (or any other valid date, in cell A1 format), 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.

Tested the formula in the most recent version of Microsoft Excel for the web and it seems to work the fine there as well.

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

Tested the formula in the most recent version of In Microsoft Excel for, the webrange of valid dates is more limited, and seems toformula will work the same therefrom January 1900 to November 9999.

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

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

Google Sheets / Microsoft Excel, 77 bytes

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

Put the month and year in cell A1 in one of the formats specified in the question (or any other valid date format), 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.

Tested the formula in the most recent version of Microsoft Excel for the web and it seems to work the fine there as well.

The Google Sheets epoch is 30 December 1899. The formula will work with dates from January 1900 to December 99999. In Microsoft Excel, the range of valid dates is more limited, and formula will work from January 1900 to November 9999.

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
add note regarding Microsoft Excel compatibility
Source Link
doubleunary
  • 2.7k
  • 1
  • 2
  • 12
Loading
Source Link
doubleunary
  • 2.7k
  • 1
  • 2
  • 12
Loading