How do I compare today's date to date in string

J

joeyej

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

Thanks,

Joe
 
M

Matt Kruse

joeyej 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?

Your question is pretty vague.

But, you will probably find the tools you need to parse, manipulate, and
compare date objects at
http://www.JavascriptToolbox.com/lib/date/

Hope that helps!
 
D

Dr John Stockton

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" ?
 
P

pegasusflightresources

You could use a simple JavaScript that uses the getDate function and
use a quick if statement comparing the real date to the date of the
option. Here is a quick script:
<script language="JavaScript">
function go()
{
var today = new Date();
var the_day = today.getDate();
var the_month = today.getMonth();
var the_year = today.getYear();
the_month = the_month + 1;
var the_option = list.options[list.selectedIndex].value;
var the_array = the_option.split(" ");
var the_othermonth = the_array[0];
if (the_othermonth = "January")
{
the_othermonth = 1;
}
if (the_other month = "February")
{
the_othermonth = 2;
}
if (the_othermonth = "March")
{
the_othermonth = 3;
}
if (the_othermonth = "April")
{
the_othermonth = 4;
}
if (the_othermonth = "May")
{
the_othermonth = 5;
}
if (the_othermonth = "June")
{
the_othermonth = 6;
}
if (the_othermonth = "July")
{
the_othermonth = 7;
}
if (the_othermonth = "August")
{
the_othermonth = 8;
}
if (the_othermonth = "September")
{
the_othermonth = 9;
}
if (the_othermonth = "October")
{
the_othermonth = 10;
}
if (the_othermonth = "November")
{
the_othermonth = 11;
}
if (the_othermonth = "December")
{
the_othermonth = 12;
}
var the_otherday = the_array[1];
the_otherday = the_otherday - ",";
var the_otheryear = the_array[2];
the_otheryear = the_otheryear - ",";
if (the_year == the_otheryear)
{
if (the_month == the_othermonth)
{
var the_difference = the_day - the_otherday;
if (the_difference < 0)
{
the_difference = the_difference - "-";
}
if (the_difference >= 2)
{
alert("whatever you want")
}
}
}
}
</script>

This script could be modified by a more adept programmer than I, but
that is the basic script. All you must do is change the alert message
to whatever you want and change the select tag to have the attribute
'onChange="go(here);"'.


P.S. PointedEars, you had better not lecture me on not quoting the
original message!!
_______________________________________

I remain your most humble and Ob't Sv't.

Patrick Reilly
1st Coy.
Colonel Seth Warner's Regiment
 
T

Thomas 'PointedEars' Lahn

P.S. PointedEars, you had better not lecture me on not quoting the
original message!!

I did not. I could lecture you on the foolishness
of your code, but you are not worth the effort.


PointedEars
 
D

Dr John Stockton

JRS: In article <[email protected]>,
dated Wed, 5 Apr 2006 15:20:53 remote, seen in
news:comp.lang.javascript, (e-mail address removed) <pegasusflig
(e-mail address removed)> posted :
var today = new Date();

This script could be modified by a more adept programmer than I,

To help in that, I have quoted above the parts of your script that might
be worth retaining.
the_otherday = the_otherday - ",";

What is that going to do? What did you think it might do? Did you test
your script?
 
P

pegasusflightresources

You notice that I did this in order to comply with the template that he
set. The template had the value read as "May 15, 2006, (Monday)
10:00am" and in order to use the split function and arrays, you must
specify where to split. Because of this reason, I was forced to use a
string subtraction function to remove the extraneous commas, which is
what that was for. I was not sure if "joeyej" was going to modify the
code in order to remove these inconsistencies, so I just used what I
could.

By the way, Pointed Ears, I had already claimed, if you had read my
post completely, that this script could be modified to be more
sophisticated and shorter by someone with more programming experience,
so you have no reason to lecture me. The most ignorant and foolish
thing that one can post is a thought that is not complete. If you have
an incomplete foundation, the argument will fall.

P.S. Dr. Stockton, why did you cite my name? I do not see a point in
citing one's name at all!

Out of complete courtesy, I would wish that no one would correct me
with arrogancy. I will and would accept comments that are suggested in
a subjective manner, but anything else is just impolite. This applies
to all of my posts.

__________________________________________

I remain you most humble and Ob't Sv't in our fight against the King.

Patrick Reilly
1st Coy.
Colonel Seth Warner's Regiment
 
R

Randy Webb

(e-mail address removed) said the following on 4/6/2006 4:25 PM:

Please quote what you are replying to.

If you want to post a followup via groups.google.com, don't use the
"Reply" link at the bottom of the article. Click on "show options" at
the top of the article, then click on the "Reply" at the bottom of the
article headers.

You notice that I did this in order to comply with the template that he
set. The template had the value read as "May 15, 2006, (Monday)
10:00am" and in order to use the split function and arrays, you must
specify where to split.
True.

Because of this reason, I was forced to use a string subtraction
function to remove the extraneous commas, which is what that was for.

1) That is not true.
2) It doesn't do what you wanted it to do.
I was not sure if "joeyej" was going to modify the code in order
to remove these inconsistencies, so I just used what I could.

If you had removed them, it wouldn't be an issue would it?
By the way, Pointed Ears, I had already claimed, if you had read my
post completely, that this script could be modified to be more
sophisticated and shorter by someone with more programming experience,
so you have no reason to lecture me. The most ignorant and foolish
thing that one can post is a thought that is not complete. If you have
an incomplete foundation, the argument will fall.

Is that why your argument is failing?

But, if you want to reply to Thomas, then reply to Thomas' post, not
John Stocktons.

P.S. Dr. Stockton, why did you cite my name? I do not see a point in
citing one's name at all!

Thats another foolish thought.

If you don't want it quoted, make it a true signature and then it won't
get quoted by a decent newsreader.
Out of complete courtesy, I would wish that no one would correct me
with arrogancy.

Out of courtesy? Are you being courteous when you don't quote what you
are replying to?
I will and would accept comments that are suggested in a subjective manner,
but anything else is just impolite. This applies to all of my posts.

We will see :)

__________________________________________

I remain you most humble and Ob't Sv't in our fight against the King.

Patrick Reilly
1st Coy.
Colonel Seth Warner's Regiment

If that is intended to be a "signature", then it should start with dash
dash space on a line of its own and then be limited to 4 lines.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top