Compare Input Date to Server Date

Discussion in 'Javascript' started by Scott Knapp, Oct 2, 2003.

  1. Scott Knapp

    Scott Knapp Guest

    Good Day -

    I have a form which sets the current date, as follows:
    <script type="text/javascript">
    xx=new Date()
    dd=xx.getDate()
    mm=xx.getMonth()+1
    yy=xx.getYear()
    mmddyy=mm+"/"+dd+"/"+yy
    document.write(mmddyy)
    </script>

    The same form has a text box where the user is asked to input a date (a
    travel date) in the format mm/dd/yyyy.

    What I would like to do is compare the user input date to the current date,
    and if the user input date is less than 2 days in advance of the current
    date, return an alert saying that the input date is not enough in advance of
    the current date.

    I checked Dr. Stockton's site
    (http://www.merlyn.demon.co.uk/js-date1.htm#DC) but was unable to find such
    a comparison.

    Any help or suggestions would be appreciated.

    Scott
     
    Scott Knapp, Oct 2, 2003
    #1
    1. Advertising

  2. Scott Knapp

    Lee Guest

    Scott Knapp said:

    >What I would like to do is compare the user input date to the current date,
    >and if the user input date is less than 2 days in advance of the current
    >date, return an alert saying that the input date is not enough in advance of
    >the current date.
    >
    >I checked Dr. Stockton's site
    >(http://www.merlyn.demon.co.uk/js-date1.htm#DC) but was unable to find such
    >a comparison.
    >
    >Any help or suggestions would be appreciated.


    There is a link on that page labeled "Date Arithmetic".
    Following it takes you to:
    http://www.merlyn.demon.co.uk/js-date2.htm

    Search that page for the section titled "Difference in Days"
     
    Lee, Oct 2, 2003
    #2
    1. Advertising

  3. JRS: In article <huXeb.2918$>, seen in
    news:comp.lang.javascript, Scott Knapp <> posted at Thu,
    2 Oct 2003 11:28:47 :-
    >Good Day -
    >
    >I have a form which sets the current date, as follows:
    ><script type="text/javascript">
    >xx=new Date()
    >dd=xx.getDate()
    >mm=xx.getMonth()+1
    >yy=xx.getYear()
    >mmddyy=mm+"/"+dd+"/"+yy
    >document.write(mmddyy)
    ></script>
    >
    >The same form has a text box where the user is asked to input a date (a
    >travel date) in the format mm/dd/yyyy.
    >
    >What I would like to do is compare the user input date to the current date,
    >and if the user input date is less than 2 days in advance of the current
    >date, return an alert saying that the input date is not enough in advance of
    >the current date.
    >
    >I checked Dr. Stockton's site
    >(http://www.merlyn.demon.co.uk/js-date1.htm#DC) but was unable to find such
    >a comparison.


    My site has more than one page on date/time in javascript. Comparison
    is not subtraction; however, comparison can be used in this case. On the
    World-Wide Web, ambiguous date formats should not be used; use YYYY/MM/DD.

    alert( Math.round( ( new Date('2003/10/05') - // date from user
    new Date().setHours(48) )/864e5)>0 ? 'OK' : 'Dud' )

    Math.round allows for the possibility of a change in Summer Time state.

    If you need 2 clear days, then replace 48 with 72.

    --
    © John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
    Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
    PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
    Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
     
    Dr John Stockton, Oct 2, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. James P.
    Replies:
    7
    Views:
    12,524
    phamtasmic
    Jul 13, 2004
  2. CZ
    Replies:
    1
    Views:
    704
    Jack Li
    Sep 23, 2005
  3. Michael Haas

    compare date field to current date

    Michael Haas, Feb 15, 2004, in forum: ASP General
    Replies:
    4
    Views:
    287
    Mike Haas
    Feb 15, 2004
  4. Robert Scheer

    Compare user date with system date

    Robert Scheer, Jul 20, 2004, in forum: Javascript
    Replies:
    1
    Views:
    110
    Dr John Stockton
    Jul 20, 2004
  5. joeyej
    Replies:
    7
    Views:
    151
    Randy Webb
    Apr 6, 2006
Loading...

Share This Page