Solved

Simple batch script for check on date

Posted on 2014-11-16
5
197 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 70

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 70

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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

The reason that corporations and businesses use Windows servers is because it supports custom modifications to adapt to the business and what it needs. Most individual users won’t need such powerful options. Here I’ll explain how you can enable Wind…
Resolve DNS query failed errors for Exchange
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
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…

635 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