JRS: In article <
[email protected]>,
dated Tue, 4 Apr 2006 13:40:29 remote, seen in
news:comp.lang.javascript said:
How do I compare today's date with this string (in my inc file) so that
I can set an alert if date choice i.e. May 15, 2006 not at least
greater than two days from current date?
<option value="May 15, 2006, (Monday), 10am">May 15, 2006, (Monday),
10am
If you had used the newsgroup FAQ before posting (see sig below), you
might not have needed to ask.
Change the value format so that it is acceptable as a parameter to new
Date() in all target browsers. ISTM that it may be enough to add the
minutes - 10:00am - but it would be more sensible to use 2006/05/15
10:00 or 10:00:00. Using the 12-hour clock within data processing is
utter folly.
Preferably, edit the change into the value as it will be when the user
is about to select it; or edit it after it has been read, for example
with
S = S.replace(/(\d+)(a|p)/, "$1:00$2")
Then just do DS = new Date(S) and compare D with a Date Object DT
holding the desired date : OK = DS > DT .
You'll have to decide whether two days ahead includes the time component
or starts at midnight, and you'll need to think about Summer Time.
You could, alternatively, with the value string in ISO/FIPS form.
generate the date-ahead in matching form and do a string comparison.
While I'm writing : has anyone any idea why "page <
http://www.merlyn.
demon.co.uk/weekinfo.htm#PW> causes my old Macintosh running Netscape
4.8 to hang solid every time" ?