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

Discussion in 'Javascript' started by joeyej, Apr 4, 2006.

  1. joeyej

    joeyej Guest

    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
     
    joeyej, Apr 4, 2006
    #1
    1. Advertising

  2. joeyej

    Matt Kruse Guest

    Matt Kruse, Apr 4, 2006
    #2
    1. Advertising

  3. JRS: In article <>,
    dated Tue, 4 Apr 2006 13:40:29 remote, seen in
    news:comp.lang.javascript, joeyej <>
    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.
     
    Dr John Stockton, Apr 5, 2006
    #3
  4. joeyej

    Guest

    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, 2006
    #4
  5. 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
     
    Thomas 'PointedEars' Lahn, Apr 6, 2006
    #5
  6. JRS: In article <>,
    dated Wed, 5 Apr 2006 15:20:53 remote, seen in
    news:comp.lang.javascript, <pegasusflig
    > 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.
     
    Dr John Stockton, Apr 6, 2006
    #6
  7. joeyej

    Guest

    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, 2006
    #7
  8. joeyej

    Randy Webb Guest

    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/
     
    Randy Webb, Apr 6, 2006
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. James P.
    Replies:
    7
    Views:
    12,646
    phamtasmic
    Jul 13, 2004
  2. TB
    Replies:
    0
    Views:
    464
  3. David C

    Compare TextBox date to today

    David C, Mar 27, 2009, in forum: ASP .Net
    Replies:
    4
    Views:
    814
    David C
    Mar 31, 2009
  4. Replies:
    8
    Views:
    239
    peashoe
    Jan 24, 2005
  5. Vinnie Davidson

    ASP Date: get records with date = today (SQL Server)

    Vinnie Davidson, Aug 13, 2005, in forum: ASP General
    Replies:
    6
    Views:
    338
    Aaron Bertrand [SQL Server MVP]
    Aug 15, 2005
Loading...

Share This Page