How can I convert installdate to a different format?


How can I convert installdate to a different format?



I am trying to run this command on cmd:


wmic:rootcli>/node:IPAddress product get name, version, vendor, installdate



IPAddress can be replaced with whatever address or hostname is desired.



The command does not give me any errors, however, it gives me installdate in MMMMYYDD form (for example, 20170801 instead of something simple like 01-Aug-2017 or 2017/08/01). I have tried to look for solutions online, but they're usually talking about system installations instead of product installations.


MMMMYYDD


20170801


01-Aug-2017


2017/08/01



I know that installdate is a string, so this is more a question of how should I convert this string into a date. I tried using '+%Y%m%d' after the installdate, but it gave me an error: Invalid GET Expression.





That is not avalid command you could execute in cmd. In general to process the output of another command you need a for /f
– LotPings
Jul 2 at 20:25





The command comes after wmic:rootcli>
– fread
Jul 2 at 20:27





As a batcher I never did use the interactive variant.
– LotPings
Jul 2 at 20:30





You cannot force the wmic console to change the returned date format. By the way: what's wrong with YYYYMMDD format?
– aschipfl
Jul 3 at 8:04


wmic


YYYYMMDD





Nothing is wrong with it, I was just wondering if there was a way to show it so that it's easier to read.
– fread
Jul 3 at 13:33




1 Answer
1



If you can use PowerShell, it is not too difficult. You can control the format you want in the ToString method.


ToString


Get-CimInstance -ClassName CIM_Product |
Select-Object -Property @{n='Name';e={$_.Name}}, @{n='Date';e={([datetime]::ParseExact($_.InstallDate,'yyyyMMdd', $null)).ToString('dd-MMM-yyyy')}}






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

PHP contact form sending but not receiving emails

PHP parse/syntax errors; and how to solve them?

iOS Top Alignment constraint based on screen (superview) height