Skip to main content
Golfed additional 6 bytes
Source Link
AdmBorkBork
  • 43.5k
  • 5
  • 103
  • 284

PowerShell v2+, 49 46 bytes

PowerShell, 49 46 40 bytes

date "$args".insert(4,'-')-U %b%y|% *per
(date $args[0].insert(4,'-')-U %b%y).ToUpper()

Try it online!

Thanks to @Joey for saving 3 bytes!

Takes input $args[0]$args as an explicit string (e.g., '201604') via command-line input. Uses the string.Insert() function to put a - in the appropriate space, and that resultant string forms input to the Get-Date cmdlet with the -Uformat parameter specifying the three-month shorthand plus two-digit year. We encapsulate that in parens, andthen tack on a .ToUpper() to make the output string capitalized. That string is left on the pipeline and printing is implicit.

Also, as pointed out, this is locale-sensitive. Here's the locale information that I'm using where this works correctly.

PS C:\Tools\Scripts\golfing> get-culture

LCID             Name             DisplayName
----             ----             -----------
1033             en-US            English (United States)
PS C:\Tools\Scripts\golfing> get-culture

LCID             Name             DisplayName
----             ----             -----------
1033             en-US            English (United States)

PowerShell v2+, 49 46 bytes

(date $args[0].insert(4,'-')-U %b%y).ToUpper()

Thanks to @Joey for saving 3 bytes!

Takes input $args[0] as an explicit string (e.g., '201604') via command-line input. Uses the string.Insert() function to put a - in the appropriate space, and that resultant string forms input to the Get-Date cmdlet with the -Uformat parameter specifying the three-month shorthand plus two-digit year. We encapsulate that in parens, and tack on a .ToUpper() to make the output string capitalized. That string is left on the pipeline and printing is implicit.

Also, as pointed out, this is locale-sensitive. Here's the locale information that I'm using where this works correctly.

PS C:\Tools\Scripts\golfing> get-culture

LCID             Name             DisplayName
----             ----             -----------
1033             en-US            English (United States)

PowerShell, 49 46 40 bytes

date "$args".insert(4,'-')-U %b%y|% *per

Try it online!

Thanks to @Joey for saving 3 bytes!

Takes input $args as an explicit string (e.g., '201604') via command-line input. Uses the string.Insert() function to put a - in the appropriate space, and that resultant string forms input to the Get-Date cmdlet with the -Uformat parameter specifying the three-month shorthand plus two-digit year. We then tack on a .ToUpper() to make the output string capitalized. That string is left on the pipeline and printing is implicit.

Also, as pointed out, this is locale-sensitive. Here's the locale information that I'm using where this works correctly.

PS C:\Tools\Scripts\golfing> get-culture

LCID             Name             DisplayName
----             ----             -----------
1033             en-US            English (United States)
Thanks to @Joey for saving 3 bytes!
Source Link
AdmBorkBork
  • 43.5k
  • 5
  • 103
  • 284

PowerShell v2+, 4949 46 bytes

(date $args[0].insert(4,'-')-fU 'MMMyy'%b%y).ToUpper()

Thanks to @Joey for saving 3 bytes!

Takes input $args[0] as an explicit string (e.g., '201604') via command-line input. Uses the string.Insert() function to put a - in the appropriate space, and that resultant string forms input to the Get-Date cmdletGet-Date cmdlet with the -fUormatformat parameter specifying the three-month shorthand plus two-digit year. We encapsulate that in parens, and tack on a .ToUpper() to make the output string capitalized. That string is left on the pipeline and printing is implicit.

Also, as pointed out, this is locale-sensitive. Here's the locale information that I'm using where this works correctly.

PS C:\Tools\Scripts\golfing> get-culture

LCID             Name             DisplayName
----             ----             -----------
1033             en-US            English (United States)

PowerShell v2+, 49 bytes

(date $args[0].insert(4,'-')-f 'MMMyy').ToUpper()

Takes input $args[0] as an explicit string (e.g., '201604') via command-line input. Uses the string.Insert() function to put a - in the appropriate space, and that resultant string forms input to the Get-Date cmdlet with the -format parameter specifying the three-month shorthand plus two-digit year. We encapsulate that in parens, and tack on a .ToUpper() to make the output string capitalized. That string is left on the pipeline and printing is implicit.

PowerShell v2+, 49 46 bytes

(date $args[0].insert(4,'-')-U %b%y).ToUpper()

Thanks to @Joey for saving 3 bytes!

Takes input $args[0] as an explicit string (e.g., '201604') via command-line input. Uses the string.Insert() function to put a - in the appropriate space, and that resultant string forms input to the Get-Date cmdlet with the -Uformat parameter specifying the three-month shorthand plus two-digit year. We encapsulate that in parens, and tack on a .ToUpper() to make the output string capitalized. That string is left on the pipeline and printing is implicit.

Also, as pointed out, this is locale-sensitive. Here's the locale information that I'm using where this works correctly.

PS C:\Tools\Scripts\golfing> get-culture

LCID             Name             DisplayName
----             ----             -----------
1033             en-US            English (United States)
Source Link
AdmBorkBork
  • 43.5k
  • 5
  • 103
  • 284

PowerShell v2+, 49 bytes

(date $args[0].insert(4,'-')-f 'MMMyy').ToUpper()

Takes input $args[0] as an explicit string (e.g., '201604') via command-line input. Uses the string.Insert() function to put a - in the appropriate space, and that resultant string forms input to the Get-Date cmdlet with the -format parameter specifying the three-month shorthand plus two-digit year. We encapsulate that in parens, and tack on a .ToUpper() to make the output string capitalized. That string is left on the pipeline and printing is implicit.