Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Compare Input Date to Server Date

Reply
Thread Tools

Compare Input Date to Server Date

 
 
Scott Knapp
Guest
Posts: n/a
 
      10-02-2003
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


 
Reply With Quote
 
 
 
 
Lee
Guest
Posts: n/a
 
      10-02-2003
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"

 
Reply With Quote
 
 
 
 
Dr John Stockton
Guest
Posts: n/a
 
      10-02-2003
JRS: In article <huXeb.2918$(E-Mail Removed)>, seen in
news:comp.lang.javascript, Scott Knapp <(E-Mail Removed)> 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(4 )/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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I compare today's date to date in string joeyej Javascript 7 04-06-2006 09:45 PM
Compare access db birthday date field with date CZ ASP .Net 1 09-23-2005 04:19 AM
Compare user date with system date Robert Scheer Javascript 1 07-20-2004 01:51 PM
how to compare current date to a future date and validate it in ASP.NET James P. ASP .Net 7 07-13-2004 10:13 PM
compare date field to current date Michael Haas ASP General 4 02-15-2004 11:30 PM



Advertisments