1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

check the date within one month

Discussion in 'DOS/Other' started by happyboy, Feb 2, 2013.

Thread Status:
Not open for further replies.
Advertisement
  1. happyboy

    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
     
  2. foxidrive

    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).
     
  3. happyboy

    happyboy Thread Starter

    Joined:
    Feb 2, 2013
    Messages:
    4
    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:
     
  4. foxidrive

    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
    )
    
    
     
  5. happyboy

    happyboy Thread Starter

    Joined:
    Feb 2, 2013
    Messages:
    4
    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!
     
  6. foxidrive

    foxidrive Banned

    Joined:
    Oct 20, 2012
    Messages:
    793
    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.
     
  7. happyboy

    happyboy Thread Starter

    Joined:
    Feb 2, 2013
    Messages:
    4
    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?
     
  8. Squashman

    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.
     
  9. Sponsor

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 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1087920

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice