# check the date within one month



## happyboy (Feb 2, 2013)

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 (Oct 20, 2012)

Does the user actually type this exact line?

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


----------



## happyboy (Feb 2, 2013)

foxidrive said:


> 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 (Oct 20, 2012)

```
@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 (Feb 2, 2013)

foxidrive said:


> ```
> @ECHO OFF
> :again
> SET /P start= Please enter the start date:
> ...


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 (Oct 20, 2012)

happyboy said:


> correct input:
> SET /P start= Please enter the start date: 05/01/2013
> SET /P end= Please enter the end date: 04/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 (Feb 2, 2013)

foxidrive said:


> 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 (Apr 4, 2003)

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.


----------

