Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compare 2 dates in a Windows batch file

How is it possible to compare 2 dates in batch files? This:

if %%newdate geq %olddate%  _do smth_

does not work.

In this case I have that
27.05.2013 is greater than 15.07.2013 and
14.07.2013 is less than 15.07.2013

Zhenya

like image 331
Zheden Avatar asked Dec 21 '22 03:12

Zheden


1 Answers

try this:

set "sdate1=%olddate:~-4%%olddate:~3,2%%olddate:~0,2%"
set "sdate2=%newdate:~-4%%newdate:~3,2%%newdate:~0,2%"
if %sdate1% GTR %sdate2% (goto there)  else echo here
like image 118
Endoro Avatar answered Jan 02 '23 22:01

Endoro