check the date within one month

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

happyboy

Thread Starter
Joined
Feb 2, 2013
Messages
4
Hi all,

I would like to write a batch file which can check the data range from the user input.

The logic should be same as below:

User input: Start date(01/01/2013), end date(31/01/2013).

if start date and end date within one month, print message "OK"

else
print message" Please input the dates with in one month" , and input the dates again

Thanks
 

foxidrive

Banned
Joined
Oct 20, 2012
Messages
793
Does the user actually type this exact line?

Start date(01/01/2013), end date(31/01/2013).
 

happyboy

Thread Starter
Joined
Feb 2, 2013
Messages
4
Does the user actually type this exact line?

Start date(01/01/2013), end date(31/01/2013).
no. The user would input the date only.

@ECHO OFF

SET /P start= Please enter the start date:
SET /P end= Please enter the end date:
 

foxidrive

Banned
Joined
Oct 20, 2012
Messages
793
Code:
@ECHO OFF
  :again
SET /P start= Please enter the start date: 
SET /P end= Please enter the end date:

if "%start:~-7%"=="%end:~-7%" (
echo OK
) else (
echo Please input the dates within the same month
goto :again
)
 

happyboy

Thread Starter
Joined
Feb 2, 2013
Messages
4
Code:
@ECHO OFF
  :again
SET /P start= Please enter the start date: 
SET /P end= Please enter the end date:

if "%start:~-7%"=="%end:~-7%" (
echo OK
) else (
echo Please input the dates within the same month
goto :again
)
Thanks for your kindly reply!
Now, I would like to ask other question if the inputted date is not in the same month.
For example:

correct input:
SET /P start= Please enter the start date: 05/01/2013
SET /P end= Please enter the end date: 04/02/2013

incorrect input:
SET /P start= Please enter the start date: 05/01/2013
SET /P end= Please enter the end date: 05/02/2013

Thanks!
 

foxidrive

Banned
Joined
Oct 20, 2012
Messages
793
correct input:
SET /P start= Please enter the start date: 05/01/2013
SET /P end= Please enter the end date: 04/02/2013

incorrect input:
SET /P start= Please enter the start date: 05/01/2013
SET /P end= Please enter the end date: 05/02/2013
Neither of those are in the same month.

If you have a task to do then explain the entire task exactly as you need it and you may get some ideas.
 

happyboy

Thread Starter
Joined
Feb 2, 2013
Messages
4
Neither of those are in the same month.

If you have a task to do then explain the entire task exactly as you need it and you may get some ideas.
Thanks ~~~
anyother question I want to ask
SET /P start= Please enter the start date (YYYY-MM-DD):
SET /P end= Please enter the end date (YYYY-MM-DD):

set /a cal_end_month= "%end:~5,2%" - 1
set /a cal_start_month= "%start:~5,2%" + 0

if the user input '2012-10-09' at the end date, there is a error "Invalid number. Numeric constants are either decimal (17),hexadecimal (0x11), or octal (021)." Could you mind to tell me the solution?
 

Squashman

Trusted Advisor
Joined
Apr 4, 2003
Messages
19,786
Well you obviously understand string parsing from the code you have written. Check to see if the 1st character is a zero and if it is Strip the leading zero from it.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Members online

Top