Difference between revisions of "Variables (PowerShell)"

Jump to navigation Jump to search
m
→‎Datetime: Minor rewording
(Initial creation - content from depreciated PowerShell page with a bit of reformatting)
 
m (→‎Datetime: Minor rewording)
Line 395: Line 395:


=== Improper (US) Formatting ===
=== Improper (US) Formatting ===
Be aware that if you live somewhere dates are normally formatted properly (eg not the USA), then Powershell (or the underlying DateTime object type) has a nasty habit of returning a string formatted with day and month swapped around when coming from a script.
Be aware that if you live somewhere dates are normally formatted properly (eg not the USA), then PowerShell (or probably the underlying DateTime object type as this sort of problem seems to rear its head at unexpected moments when working on Windows) has a nasty habit of returning a string formatted with day and month swapped around when coming from a script.


If you do a <code> Get-Date </code> it all looks fine, but then you output a DateTime object in a script to some text and its wrong.  Add the <code> .ToString() </code> method to the end at it'll sort itself, though quite why when Powershell is converting the object into a string anyway, the object needs to be explicitly told to fix the issue, seems a bit superfluous.
If you do a <code> Get-Date </code> it all looks fine, but then you output a DateTime object in a script to some text and its wrong.  Add the <code> .ToString() </code> method to the end at it'll sort itself, though quite why when Powershell is converting the object into a string anyway in order to display, should the object need to be explicitly told to fix the issue, seems a bit superfluous.  I obviously don't understand what the underlying bug is!
 
If your dates are getting mixed up, it may not be your mistake, and it may be that you've fallen fowl of the problem as well.


=== Formatting ===
=== Formatting ===

Navigation menu