Solved

Simple batch script for check on date

Posted on 2014-11-16
5
188 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

746 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

10 Experts available now in Live!

Get 1:1 Help Now