Skip to main content
added 621 characters in body
Source Link
Jeff Zeitlin
  • 469
  • 1
  • 3
  • 11

This works on my PowerShell 5 on my computer; I can't get it working on TIO:

PowerShell 5, 97 bytes

function s($m,$d){1+(New-Timespan -st (Get-Date -day 1 -mo 1) -e (Get-Date -day $d -mo $m)).Days}

Call as s 2 11 for the example date (month before day-of-month).

Golfed by @mazzy, 82 bytes

PowerShell, 82 bytes

param($m,$d)1+(New-Timespan -st (Date -day 1 -mo 1) -e (Date -day $d -mo $m)).Days

Try it online!

The golfing relies on an alias or implementation of command (Date) that does not exist in a default Windows 10 installation of PowerShell 5. The TIO PowerShell is PowerShell 6 on Linux.

This works on my PowerShell 5 on my computer; I can't get it working on TIO:

PowerShell 5, 97 bytes

function s($m,$d){1+(New-Timespan -st (Get-Date -day 1 -mo 1) -e (Get-Date -day $d -mo $m)).Days}

Call as s 2 11 for the example date (month before day-of-month).

This works on my PowerShell 5 on my computer; I can't get it working on TIO:

PowerShell 5, 97 bytes

function s($m,$d){1+(New-Timespan -st (Get-Date -day 1 -mo 1) -e (Get-Date -day $d -mo $m)).Days}

Call as s 2 11 for the example date (month before day-of-month).

Golfed by @mazzy, 82 bytes

PowerShell, 82 bytes

param($m,$d)1+(New-Timespan -st (Date -day 1 -mo 1) -e (Date -day $d -mo $m)).Days

Try it online!

The golfing relies on an alias or implementation of command (Date) that does not exist in a default Windows 10 installation of PowerShell 5. The TIO PowerShell is PowerShell 6 on Linux.

Source Link
Jeff Zeitlin
  • 469
  • 1
  • 3
  • 11

This works on my PowerShell 5 on my computer; I can't get it working on TIO:

PowerShell 5, 97 bytes

function s($m,$d){1+(New-Timespan -st (Get-Date -day 1 -mo 1) -e (Get-Date -day $d -mo $m)).Days}

Call as s 2 11 for the example date (month before day-of-month).