PDA

View Full Version : date comparison



BubikolRamios
06-19-2010, 06:31 PM
Why alert('hua'); does not pop up ?


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');
}

Philip M
06-19-2010, 06:50 PM
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

BubikolRamios
06-19-2010, 07:05 PM
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 ?

Philip M
06-19-2010, 07:20 PM
[QUOTE=BubikolRamios;966029]so, do I have to convert date objects to string in order to do this ?
[QUOTE]

Try this:-


<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>

BubikolRamios
06-19-2010, 08:43 PM
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.