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…