manav08
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.
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.
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?
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?
ASKER
actually when I typed
echo %date:~-4%%date:~-10,2%%da te:~-7,2%
the output was 20141611
This technically means that 20141512 is less than 20141611, which is not actually true :(
echo %date:~-4%%date:~-10,2%%da
the output was 20141611
This technically means that 20141512 is less than 20141611, which is not actually true :(
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
You are a scripting genius. Thank you
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%%d