R – Manipulating time in a batch file

batch-filescriptingwindows

I was wonderin' if someone would be able to help with this lil' batch file here. I'm trying to check when the last successful Windows Update was .
Here is the code here ..

@ECHO OFF
SETLOCAL
SET RegKey=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion
SET RegKey=%RegKey%\WindowsUpdate\Auto Update\Results\Install
FOR /F "skip=1 tokens=2*" %%A IN ('REG Query "%RegKey%" /v "LastSuccessTime"') DO SET LastWUpd=%%B
IF "%~1"=="" ECHO Last successful Windows Update: %LastWUpd%
PAUSE
ENDLOCAL & SET LastWUpd=%LastWUpd%
IF "%~1"=="" GOTO:EOF

And this is the output I get:

Last successful Windows Update:
2009-10-14 09:02:52

I was wonderin' if there was a way to calcualte the difference from the time now ? So that the line can be changed to read:

Last successful Windows update was x
years x months x days x hours x mins
ago
If that would be possible that would be awesome.

Thanks in advance guys,

Methical

Best Answer

I found this article, with an command line utility to perform date/time calculations and help you to resolve your problem.

However, can you consider using PowerShell to complete same task? I'm not an expert on subject but since you can run .NET managed code on PS, you should be able to complete tasks like that more easily.