Answer the question
In order to leave comments, you need to log in
How to compare two dates in dat?
Hello colleagues.
There is a task of comparison of two dates.
I get the first date like this:
set now=%date%
I get the second one like this:
FOR /F "tokens=* USEBACKQ" %%a IN (`net user /DOMAIN %username% ^| findstr /C:"Password expires"`) DO (set p=%%a)
set pass=%p:~29,-9%
Answer the question
In order to leave comments, you need to log in
Batniks do not know how to work with dates. All variables are strings.
Yes, it set /a
can perform integer arithmetic, but the result is still a string.
You need to convert the dates to the number of days since the beginning of the epoch, and then they can be compared using standard means.
The easiest way is to use more advanced tools for these purposes that can work with dates, for example, powershel, JS, VBS - these scripts can be called from the batch file if desired.
But if you really want to, you can count the batch file. The calculation algorithm is on the wiki. The code can be pulled from here - https://www.robvanderwoude.com/files/datediff_nt.txt
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question