472,328 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,328 software developers and data experts.

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 22946
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: alexis | last post by:
Hi, In a form I have the curent date <input name="datetoday" type="hidden" value="<? echo date("d/m/Y"); ?>"> and <input type=text...
0
by: Stephen | last post by:
Can someone help me. I'm trying to use the following validator control and compare a date to a date defined in the code-behind page. My code is...
9
by: Rich | last post by:
Thanks for the Help in my previous post. I've been working on this and it's almost what I want. I want to obtain the user's current age by...
5
by: Darrel | last post by:
I'm trying to check a few fields in my SQL query to ensure that they fall between a range (namly that today's date is greater than one field and...
12
by: Assimalyst | last post by:
Hi, I have a working script that converts a dd/mm/yyyy text box date entry to yyyy/mm/dd and compares it to the current date, giving an error...
6
by: ar555 | last post by:
I have a page with two textfields for dates (dateFrom, dateTo) which user inputs from a small popup calendar. Dates are in dd/mm/yyyy format. When...
4
by: jmarcrum | last post by:
Hi everyone!! I have a continuous form that allows users to select a record and chnage the DATE that the record is assigned to another DATE within...
11
by: soni2926 | last post by:
Hi, I have a function where i need to check the date passed in is within 90days of today. Could someone help me get this to work, how do i do the...
25
by: Brian | last post by:
I have a datetimepicker formated for just time, the user selects the time. I want to compare if that time is between midnight and 8 am dtmTime...
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
1
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.