469,267 Members | 1,508 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,267 developers. It's quick & easy.

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

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

Apr 4 '06 #1
7 22825
joeyej wrote:
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!

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Apr 4 '06 #2
JRS: In article <11*********************@i39g2000cwa.googlegroups. com>,
dated Tue, 4 Apr 2006 13:40:29 remote, seen in
news:comp.lang.javascript, joeyej <jo*************@quinnipiac.edu>
posted :
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" ?

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Apr 5 '06 #3
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

Apr 5 '06 #4
pe********************@gmail.com wrote:
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
Apr 6 '06 #5
JRS: In article <11*********************@i39g2000cwa.googlegroups. com>,
dated Wed, 5 Apr 2006 15:20:53 remote, seen in
news:comp.lang.javascript, pe********************@gmail.com <pegasusflig
ht*********@gmail.com> posted :
<script var today = new Date(); </script> 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?
Patrick Reilly

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Apr 6 '06 #6
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

Apr 6 '06 #7
pe********************@gmail.com 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.

<URL: http://www.safalra.com/special/googlegroupsreply/ >
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.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Apr 6 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by alexis | last post: by
reply views Thread by Stephen | last post: by
9 posts views Thread by Rich | last post: by
5 posts views Thread by Darrel | last post: by
12 posts views Thread by Assimalyst | last post: by
6 posts views Thread by ar555 | last post: by
11 posts views Thread by soni2926 | last post: by
25 posts views Thread by Brian | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.