Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Last Week Day Of The Month

Introduction

This challenge was inspired by a seemingly simple task requested at work that couldn't easily be done in Microsoft Teams. At least not from what we could find!

Task

Your task, if you choose to accept it, is to output the last week day of any month in any year.

Input

You can input the desired month/year in whatever format you like, but it must take in an input. Having these hard-coded into the calculations doesn't count!

Input examples include but are not limited to:

  • 08/2023
  • October 1678
  • 1/2067

Output

Your output must be the last week day of the month in the below format:

Tuesday 31st

Test cases

Input Output
10/2023 Tuesday 31st
February 2017 Tuesday 28th
09/1674 Friday 28th
1/2043 Friday 30th

Assumptions / Stipulations

  • You can assume the inputs are always in a workable format and not null
  • Calendar is the Gregorian Calendar
  • Monday, Tuesday, Wednesday, Thursday and Friday are all week days. Saturday and Sunday are NOT valid week days for this task
  • You can ignore public holidays

PS. I got the test cases from timeanddate.com

Current Winner (28th November 2023)

PHP - Kaddath - 55 Bytes https://codegolf.stackexchange.com/a/266340/91342

Answer*

Draft saved
Draft discarded
Cancel
6
  • \$\begingroup\$ 133 bytes \$\endgroup\$ Commented Oct 27, 2023 at 16:42
  • \$\begingroup\$ @SuperStormer Thank you very much, updated \$\endgroup\$ Commented Oct 27, 2023 at 16:51
  • \$\begingroup\$ Unfortunately, 153 bytes to handle the "st"/"th" properly. \$\endgroup\$ Commented Oct 27, 2023 at 18:04
  • \$\begingroup\$ @SuperStormer Thanks, updated \$\endgroup\$ Commented Oct 27, 2023 at 18:07
  • 2
    \$\begingroup\$ -2 bytes: d.strftime('%A %d')+'tsht'[d.day>30::2] \$\endgroup\$ Commented Oct 27, 2023 at 21:00

AltStyle によって変換されたページ (->オリジナル) /