Your sample date is ambiguous.
To compare a date (without converting to datetime type or serial) you need to order it by yyyy,MM,dd.
What is your 02/02/2018
meant to be MM/dd/yyyy
? Or dd/MM/yyyy
?
:: Q:\Test\2019\05\02\SO_55934933.cmd
@Echo off
Call :GetDate Srv "\\server\share\folder\file.txt"
Call :GetDate PC "X:\folder\file.txt"
if not defined Srv (Echo couldn't obtain server date &pause&Exit /b 1)
if not defined PC (Echo couldn't obtain local PC date&pause&Exit /b 1)
if %Srv% geq %PC% (
Echo Server date %Srv% newer or equal to PC date %PC%
) else (
Echo Server date %Srv% older than PC date %PC%
)
Goto :Eof
:GetDate and reverse order
set /p "Dt="<%2
:: assuming dd/MM/yyyy
For /f "tokens=1-3delims=/" %%D in ("%DT%") Do Set "%1=%%F%%E%%D"
:: assuming dd/MM/yyyy
:: For /f "tokens=1-3delims=/" %%D in ("%DT%") Do Set "%1=%%F%%D%%E"
The batch contains both variants, MM/dd/yyyy
is commented out.
Sample output:
> Q:\Test\2019\05\02\SO_55934933.cmd
Server date 20180203 newer or equal to PC date 20180202