Home > database >  Batch script to calculate remaining days
Batch script to calculate remaining days

Time:12-07

In Windows Batch scripting,

I want to extract the date after "until:" and with the current date I want to calculate how many days remaining until the certificate expires.

Serial number: 1300000119b2de558ca060bb5e000000000119
Valid from: Mon Jun 14 20:17:27 EET 2021 until: Thu Jun 08 14:36:44 EET 2023
Certificate fingerprints:

CodePudding user response:

After spent couple of hours and search in internet, I've completed my script. Of course it is not perfect, I'm open to improvements. But I tested many scenarios it looks okay and enough to me. Thanks.

@ECHO OFF

for /F "delims=" %%a in ('findstr "until:" output.crt') do set var=%%a
echo %var%
ECHO ----------------
set "var2=%var:*Until: =%"
echo %var2%
ECHO ----------------
set "certyear=%var2:*EET =%"
echo            
  • Related