'en-NZ culture' - default date format 'dd/MM/yyyy'

When run on PowerShell(7) …


PS> $datePattern = '\d{4}-\d{2}-\d{2}'
'Today is 1999-12-31' -replace $datePattern, { [datetime]$PSItem.value }
... produces:- 
'Today is 12/31/1999 00:00:00'
rather than (my Locale Pattern):-
'Today is 31/12/1999 00:00:00'

when:-

PS > Get-Culture -Debug
... produces:- 

LCID             Name             DisplayName
----             ----             -----------
5129             en-NZ            English (New Zealand)

… Am I wrong?

In the “en-NZ” culture, the default date format is “dd/MM/yyyy”. When converting the date string ‘1999-12-31’ to a datetime object (cast … [datetime]), PowerShell uses the default date format of the current culture to display the datetime object. Therefore, ‘12/31/1999 00:00:00’ should be ‘31/12/1999 00:00:00’.
Is this not the case? Could this be a PowerShell bug? How do I test this possibility?

I was excited to (finally) discover PowerShell a couple of weeks ago … enjoying, the (for me, very steep) ‘learning curve’ … has to be said … 76 year old, of dubious intellectual stature … 35 year photography career and a retirement plan to unite past clients, with their original (now being digitised by me) pictures, which involves a significant amount of metadata and general data manipulation…

Don,
Welcome to the forum. :wave:t3:

When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in PowerShell.org 1 <---- Click :point_up_2:t4: :wink:

How do you populate $PSItem?

And what is it what you’re actually trying to do? There might be another/a better way. :wink:

You can always format a date to your particular needs:

$DateTime = Get-Date
$DateTime.ToString('dd\/MM\/yyyy HH:mm:ss')

I have made a first forum submission … did not format code … how do I edit this submission to rectify?

image

If it’s not there don’t bother. I’ve heard from users that they couldn’t edit their post later on.

How about your issue? Could you solve it in the meantime?

Thanks Olaf … no response so far but I am still trying to increase my knowledge … plenty yet to learn …

What do you mean? What about my first reply? ¯\_(ツ)_/¯