Link to home
Start Free TrialLog in
Avatar of manav08
manav08Flag for Australia

asked on

Simple batch script for check on date

Hi Guys,

I would like to create a simple batch file which will do the following -
If today's date is greater than 14/11/2014 then execute a following task.

I have tried the following

IF "%Date%" GTR "17/11/2014" ECHO YES

But this doesn't seem to work and will echo yes all the time.
Any help would be appreciated and I dont want to use VBSCRIPT.
Avatar of Qlemo
Qlemo
Flag of Germany image

Two issues are causing that. First you are comparing two strings.
Next, %date% often has the weekday prefixed.

For a DOS-only solution it is necessary to extract the date parts and compare tbem correctly:
  if "%date:~-4%%date:~-10,2%%date:~-7,2%" GTR "20141114" echo yepp
Avatar of manav08

ASKER

Hi Qlemo,

We use UK DATE FORMAT i.e. 14/11/2014.
So when I type %DATE% in command prompt, I get the following : Sun 16/11/2014

How will I change your script please?
Avatar of manav08

ASKER

actually when I typed
echo %date:~-4%%date:~-10,2%%date:~-7,2%
the output was 20141611

This technically means that 20141512 is less than 20141611, which is not actually true :(
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of manav08

ASKER

You are a scripting genius. Thank you