nesher13
asked on
Converting result of the output to needed format
I get the output of the variable $WinInsDate in the format "20120509120504.000000 +180"
how can I convert it to a format similar to output command
Get-Date -DisplayHint date ?
how can I convert it to a format similar to output command
Get-Date -DisplayHint date ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
to footech
how can I convert the resulting format into a format mm/dd/yyyy ?
how can I convert the resulting format into a format mm/dd/yyyy ?
Both expressions will result in a datatime, which again can be formatted by e.g. stuffing into get-date -format .... or using the -f operator (which will automatically use the date format set up in the OS):
get-date -format 'MM/dd/yyyy' $yourDateTime
'{0:d}' -f $yourDateTime
get-date -format 'MM/dd/yyyy' $yourDateTime
'{0:d}' -f $yourDateTime
ASKER
I found a pretty simple solution to the second part of the question
PS C:\>$a = (Get-WmiObject Win32_OperatingSystem)
PS C:\>$a.converttodatetime($ a.installd ate)
Sunday, August 04, 2013 5:46:45 PM
PS C:\>$a.converttodatetime($ a.installd ate) | get-date -format d
8/4/2013
PS C:\>$a = (Get-WmiObject Win32_OperatingSystem)
PS C:\>$a.converttodatetime($
Sunday, August 04, 2013 5:46:45 PM
PS C:\>$a.converttodatetime($
8/4/2013
ASKER
I've requested that this question be closed as follows:
Accepted answer: 0 points for nesher13's comment #a39520350
Assisted answer: 500 points for footech's comment #a39517538
for the following reason:
footech answer gave me the basis for solving the problem
Accepted answer: 0 points for nesher13's comment #a39520350
Assisted answer: 500 points for footech's comment #a39517538
for the following reason:
footech answer gave me the basis for solving the problem
ASKER
footech answer gave me the basis for solving the problem
So your date literal "20120509120504.000000 +180" was wrong? The corresponding WMI date literal is "20120509120504.000000+180 " (no space, as mentioned above).
If you want to do it the hard, but most flexible way:
Open in new window
I've ignored the milli/microseconds stuff.