Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: date comparison

  1. #1
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,960
    Thanks
    120
    Thanked 76 Times in 76 Posts

    date comparison

    Why alert('hua'); does not pop up ?
    Code:
    var cur_date = new Date();
        cur_date.setSeconds(0);
        cur_date.setHours(0);
        cur_date.setMilliseconds(0);
        cur_date.setMinutes(0);
        
        alert(cur_date);
        alert(new Date(cur_date.getFullYear(),cur_date.getMonth(),cur_date.getDate()));
    
        if (new Date(cur_date.getFullYear(),cur_date.getMonth(),cur_date.getDay()) == cur_date )
        {
          alert('hua');
        }
    Found a flower or bug and don't know what it is ?
    agrozoo.net galery
    if you don't spot search button at once, there is search form:
    agrozoo.net galery search

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,918
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by BubikolRamios View Post
    Why alert('hua'); does not pop up ?
    Because cur_date is an object, not a string subject to comparison.

    Is it your sister or your brother who is his dad? - Victoria Derbyshire, Radio 5 Live
    Last edited by Philip M; 06-19-2010 at 06:59 PM.

  • #3
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,960
    Thanks
    120
    Thanked 76 Times in 76 Posts
    so, do I have to convert date objects to string in order to do this ?

    In java there is 'equals' operator , don't think in js is something similar ?
    Found a flower or bug and don't know what it is ?
    agrozoo.net galery
    if you don't spot search button at once, there is search form:
    agrozoo.net galery search

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,918
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    [QUOTE=BubikolRamios;966029]so, do I have to convert date objects to string in order to do this ?
    [QUOTE]

    Try this:-

    Code:
    <script type = "text/javascript">
    
    var myDate=new Date(2010,3,11);  // or whatever date is relevant
    myDate.setHours(0);
    myDate.setMinutes(0);
    myDate.setSeconds(0);
    myDate.setMilliseconds(0);
    var today = new Date();
    if (myDate>today)  {
    alert ("Today is before 11th February June 2010");
    }
    else  {
    alert ("Today is on or after 11th February 2010");
    }
    </script>
    Last edited by Philip M; 06-19-2010 at 07:24 PM.

  • #5
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,960
    Thanks
    120
    Thanked 76 Times in 76 Posts
    Need exactly equality comparison.
    ,so that datepicker can mark today date as special on table of posible choices.

    Never mind, converted both to string and it works.

    Thanks.
    Found a flower or bug and don't know what it is ?
    agrozoo.net galery
    if you don't spot search button at once, there is search form:
    agrozoo.net galery search


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •