C:\_G\WWW\~ELISANET\INFO\tscmd195.html
<https://www.salminet.fi/info/tscmd195.html>
Copyright © 2003- by Prof. Timo Salmi  
Last modified Tue 11-Aug-2026 16:27:22

 
Assorted NT/2000/XP/.. CMD.EXE Script Tricks
From the html version of the tscmd.zip 1cmdfaq.txt file
To the Description and the Index
 

This page is edited from the 1cmdfaq.txt faq-file contained in my tscmd.zip command line interface (CLI) collection. That zipped file has much additional material, including a number of detached .cmd script files. It is recommended that you also get the zipped version as a companion.

Please see "The Description and the Index page" for the conditions of usage and other such information.



195} Getting the elapsed time using a PowerShell-aided command-line

  @echo off & setlocal enableextensions
  call :GetDateTimePS start_
  echo Whatever ...
  pause
  call :GetDateTimePS endat_
  call :TimeDiffPS "%start_%" "%endat_%" elapsed_
  echo Start at "%start_%"
  echo Ended at "%endat_%"
  echo %%elapsed_%%=%elapsed_%
  endlocal & goto :EOF

  :: The indentation is essential to avoid incorrect syntax
  :GetDateTimePS
  setlocal
  for /f "usebackq delims=" %%A in (`powershell -NoLogo -NoProfile -Command ^
    "Get-Date -Format 'dd.MM.yyyy HH:mm:ss'"`) do (
      set "result_=%%A")
  endlocal & set "%1=%result_%" & goto :EOF

  :TimeDiffPS
  setlocal
  for /f "usebackq tokens=1-3 delims=" %%a in (`
    powershell -NoProfile -Command ^
      "$a=[datetime]::ParseExact('%~1','dd.MM.yyyy HH:mm:ss',$null);"
      "$b=[datetime]::ParseExact('%~2','dd.MM.yyyy HH:mm:ss',$null);"
      "($b-$a).ToString()"`) do (set result_=%%a)
  endlocal & set "%3=%result_%" & goto :EOF

The output might be e.g.
  Whatever ...
  Press any key to continue . .
  Start at "09.08.2026 19:08:00"
  Ended at "09.08.2026 19:20:36"
  %elapsed_%=00:12:36

Also see item#030 for a non-PowerShell solution.

[Previous] [Next]

C:\_G\WWW\~ELISANET\INFO\tscmd195.html
C:\_G\WWW\~ELISANET\FTPCMD\TSALMI.CMD /tscmd195
C:\_E\ARCZIP\COPYTONE.CMD /~info
https://www.salminet.fi/info/tscmd195.html
file:///c:/_g/www/~elisanet/info/tscmd195.html