How does one get date-1 and format it to mm-dd-yyyy in PowerShell?
Example: If today is November 1, 2013, and I need 10-31-2013 in my code.
I've used AddDays(-1) before, but I can't seem to get it to work with any formatting options.
How does one get date-1 and format it to mm-dd-yyyy in PowerShell?
Example: If today is November 1, 2013, and I need 10-31-2013 in my code.
I've used AddDays(-1) before, but I can't seem to get it to work with any formatting options.
You can use the .tostring() method with datetime format specifiers to format to whatever you need:
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx
There're few additional methods available as well e.g.:
$dte.AddDays(-45).Day
I think this is only partially true. Changing the format seems to switch the date to a string object which then has no methods like AddDays to manipulate it. So to make this work, you have to switch it back to a date. For example: