How do I compare numbers in windows command line?

Hi

How do I compare numbers in windows command line?
Why doesn't this work? this always print 2

Thanks
Jamie

@echo off

SET AA=1380087074
SET BB=1380084626

echo %AA%
echo %BB%

IF "%AA%" GTR %BB% (
	echo "1"
) ELSE (
	echo "2"
)

IF "%BB%" GTR %AA% (
	echo "1"
) ELSE (
	echo "2"
)

Open in new window

jamie_lynnAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Steve KnightIT ConsultancyCommented:
You need to remove the " " around your first part of the IF.  What you are saying at the moment is something like;

set "1" GTR 2

and a " character is always going to be less than a number character in ASCII order...

SET AA=1380087074
SET BB=1380084626

echo %AA%
echo %BB%

IF %AA% GTR %BB% (
	echo 1
) ELSE (
	echo 2
)

IF %BB% GTR %AA% (
	echo 1
) ELSE (
	echo 2
)

Open in new window



There are quite low limits on the numeric handling in batch too btw.

Steve

[Edits - sorry browser playing up]
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jamie_lynnAuthor Commented:
Thanks!!! I can't believe I didn't see that. Looking at it for over an hour and couldn't figure it out.
0
Bill PrewCommented:
Keep in mind that the DOS command line can only deal with integer numbers, and only number in the range  2147483647 to -2147483648 (since it is limited to 32 bit integers with one of those bits reserved for sign).  As a result some things don't work well when you get above these sizes.  Here are a couple of tests you can try from a command line to see what I mean.

set i=2147483646
set i
set /a i+=1
set /a i+=1


if 2147483648 GTR 2147483647 echo YES

~bp
0
Steve KnightIT ConsultancyCommented:
No problem.  As Bill clarified be careful as very easy to get into odd errors.... big numbers, non-numeric characters in there meaning text comparison, and leading zeroes will cause text comparison too (and treating as octal in calculations).  All good fun!
0
jamie_lynnAuthor Commented:
My numbers are 10 digit epoch time in seconds so the numbers will be in range.

Thanks Guys!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.