How to set correctly date short format?

Welcome Forums General PowerShell Q&A How to set correctly date short format?

Viewing 2 reply threads
  • Author
    • #219666
      Topics: 1
      Replies: 1
      Points: 15
      Rank: Member

      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.

    • #219678
      Topics: 4
      Replies: 2247
      Points: 5,484
      Helping Hand
      Rank: Community MVP

      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.


    • #219729
      Topics: 3
      Replies: 340
      Points: 1,120
      Helping Hand
      Rank: Community Hero

      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;”></p>
      Now I thought I was onto something with this

      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

Viewing 2 reply threads
  • You must be logged in to reply to this topic.