How can I get Get-Date to produce '/' as the date separator? There is a requirement to produce a en-US centric date format. It appears that PowerShell will always use the regional settings regardless of the format specified. It is set to '-' on my system, but I need to produce a date using '/'.
PS C:\src> Get-Date -Format MM/dd/yyyy
06-26-2017
PS C:\src> Get-Date -Format "MM/dd/yyyy"
06-26-2017
PS C:\src> Get-Date -Format 'MM/dd/yyyy'
06-26-2017
PS C:\src> Get-Date -Format "MM`/dd`/yyyy"
06-26-2017
The date separator is set to '-' on my machine. I do not find a Set-UICulture command.
PS C:\src> (Get-UICulture).DateTimeFormat.DateSeparator
-
In the format string, /
represents the current UICulture date separator. To force it to be explicitly the /
character, you must escape it using the \
character:
Get-Date -Format "MM\/dd\/yyyy"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With