I have a text file which contains a date (the format would be like 1/1/2015 or 01/01/2015... both formats are acceptable).
Now I have to write a batch script which will compare dates. It has to show that the dates 1/1/2015 and 01/01/2015 are the same.
How can I do this?
This is likely not the most elegant way, but in the interest of getting you a working sample - this performs the comparison you need:
This sample could easily be used as a subroutine which takes in
Date1
andDate2
as variables and then sets a return variable for use in the main program.Note that the order of month or day doesn't matter as far as the script is concerned.
Month1
could just as easily be namedDate1Part1
(etc.) and the script would work just fine.This method use a subroutine that allows you to compare two dates with any comparison of
if
command, likeleq
,gtr
, etc.This code assume that the date format is MM/DD/YYYY. If your date format is different, just change the
m1
,d1
,m2
,d2
variables in theset /A
command with the proper order.