Solved

Simple batch script for check on date

Posted on 2014-11-16
5
191 Views
Last Modified: 2014-11-16
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.
0
Comment
Question by:manav08
  • 3
  • 2
5 Comments
 
LVL 68

Expert Comment

by:Qlemo
ID: 40445582
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
0
 
LVL 11

Author Comment

by:manav08
ID: 40445586
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?
0
 
LVL 11

Author Comment

by:manav08
ID: 40445590
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 :(
0
 
LVL 68

Accepted Solution

by:
Qlemo earned 500 total points
ID: 40445598
Of course, I did not spot you are using a "correct" date format, which is at least consequently "wrong" in regard of sorting, and not that mixed-up stuff of US :D

Each %date....% is one date part. So just arrange them different, and you are set:
  if "%date:~-4%%date:~-7,2%%date:~-10,2%" GTR "20141114" echo yepp
0
 
LVL 11

Author Closing Comment

by:manav08
ID: 40445623
You are a scripting genius. Thank you
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Utilizing an array to gracefully append to a list of EmailAddresses
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now