Get-Culture and get-UICulture showing different results!

This topic contains 4 replies, has 3 voices, and was last updated by  Derf User 2 weeks, 4 days ago.

  • Author
    Posts
  • #83155

    Derf User
    Participant

    Code is this:

    $test = '01/10/2017'
    Write-Host $test  #Shows 01/10/2017
    $test = $test.Date.ToLongDateString()
    Write-Host $test #Shows 10 January 2017 instead of 1 October 2017

    Get-Culture shows en-GB (correct) but Get-UICulture shows en-US
    On Windows the Locale is set to en-GB so how to I tell Powershell ISE to switch to this?

  • #83164

    Richard Siddaway
    Moderator

    What version of windows and PowerShell are you running? I used to have this issue – and you can't change the UICulture – but on my Windows 10 machine with PowerShell 5.1 both cmdlets show en-GB as they should

  • #83206

    Derf User
    Participant

    I have Windows 7 Pro and Powershell 5. This problem is really causing chaos as all dates in Windows are dd/MM/yyyy so, for example, when I retrieve an environment variable (in PS) set to '13/10/20' I get "String was not recognized as a valid DateTim".
    Is there maybe a Registry entry I can change?

  • #83209

    Alex Aymonier
    Participant

    From a quick google i found the following. The short version is that you change UICulture with the Language control panel, and Culture with the Region control panel. Culture just affects things like date / time / currency / number formats; UICulture is the actual language pack.

  • #83212

    Derf User
    Participant

    I agree; the problem being that everything is set to UK english in both of those places. I have done a temporary fix by adding a function to 'split' the date (reversing the Month/Day ones) before calling ToLongDateString() which works.

You must be logged in to reply to this topic.