How to set correctly date short format?

For years, I’ve been using the following PowerShell code in my profile file to make sure I’m using ISO 8601 format for date.

$culture = Get-Culture
$culture.DateTimeFormat.ShortDatePattern = 'yyyy-MM-dd'
Set-Culture $culture

I’ve just installed PowerShell 7 and suddenly this code does not work anymore. I got this error message:

2 | $culture.DateTimeFormat.ShortDatePattern = ‘yyyy-MM-dd’
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Exception setting “ShortDatePattern”: “Instance is read-only.”

So, what is the new and correct way of doing this in PowerShell 7? Please.

When you crosspost the same question at the same time to different forums you should at least post links to the other forums along with your question to avoid people willing to you help making their work twice or more.

https://social.technet.microsoft.com/Forums/en-US/99a81774-e634-4263-be84-23a572208a3f/how-to-set-correctly-date-short-format?forum=winserverpowershell

Thanks

This is interesting. Based on the closed issue linked below, it is being stated that it’s read only, always has been, not a bug, and working as designed.

However that is not true, in 5.1 you are able to set it the way you show.
<p style=“text-align: left;”>https://imgur.com/VXXYwar</p>
Now I thought I was onto something with this

https://imgur.com/g37C9BR

As you can see it didn’t error but it didn’t change either. I’d say there is a bug, either in Windows Powershell for it working, or in pwsh 6/7 for it not.I tested on 6.2.1