473,796 Members | 2,628 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 23068
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************ *********@i39g2 000cwa.googlegr oups.com>,
dated Tue, 4 Apr 2006 13:40:29 remote, seen in
news:comp.lang. javascript, joeyej <jo************ *@quinnipiac.ed u>
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.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.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="JavaS cript">
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.selectedIn dex].value;
var the_array = the_option.spli t(" ");
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(h ere);"'.
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.c om 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************ *********@i39g2 000cwa.googlegr oups.com>,
dated Wed, 5 Apr 2006 15:20:53 remote, seen in
news:comp.lang. javascript, pe************* *******@gmail.c om <pegasusflig
ht*********@gma il.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.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.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.c om 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.c om, 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.javas cript 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
21533
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 name="datebox" size=15> The date format is d/m/Y (day/month/year) in both case Now my problem is that i want to know if 'datebox' is valid, that means after 'datetoday'.
0
1277
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 below along with my error message I get when the page is rendering in the browser. Has anyone any idea what I've done wrong? <asp:CompareValidator ID=cvDate Font-Size=small ForeColor=red Runat=server ErrorMessage="Please work" Operator=LessThanEqual Type=Date ControlToValidate=txtStartDate...
9
3943
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 comparing their date of birth (user inputs) to the current date. I know how to get the Current Date but I'm not finding how to calculate the Current Date minus the User's Birthday.
5
2305
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 less than another field.) This is what I have: ========================================= dim strCurrentDate as String = microsoft.VisualBasic.DateAndTime.Today().ToString("mm/dd/yyyy")
12
29474
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 through an asp.net custom validator, it is as follows: function doDateCheckNow(source, args) { var oDate = document.getElementById(source.controltovalidate); // dd/mm/yyyy
6
5329
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 user clicks on submit button, function is called to validate these dates dateTo > date From dateTo <> dateFrom dateFrom > today I write a function , but..... function search() {
4
1938
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 the same year. The button is called "Change plan Date Within 2008." The user can select a particular record, click that button and a new small form appears that displays the current Plan Date and a textbox for entering a new Plan Date. 'If the New Plan Date is earlier than today's date, this...
11
2724
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 90 days compare with today? <script language='javascript'> function CheckDate(productDate) { var dateVar = new Date(productDate); //alert(dateVar); var today = new Date();
25
4546
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 #11:59:59 PM# and dtmTime < #08:00:00 AM# this evaluates to true when the time is not greater than dtmTime #9:32:34 PM# Why is that? and How can I get this to work? Brian
0
9673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10217
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10168
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10003
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9047
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5440
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5568
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4114
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.