all groups > flash actionscript > may 2004 >
You're in the

flash actionscript

group:

problem comparing equality of dates-is this a bug


problem comparing equality of dates-is this a bug fat steve
5/27/2004 9:53:32 PM
flash actionscript: Hi, I'm trying to compare two dates that are the same, and perform a specific
action if they are the same. Here's my code:
When they're equal Flash says that they aren't. Why?

Is this a bug b/c it makes no sense! >:(

var d = new Date(2004, 3, 17);
var e = new Date(2004, 3, 17);
trace(d<e);
trace(e<d);
if (d == e) {
trace("equal");
} else {
trace("not equal");
}
Re: problem comparing equality of dates-is this a bug AJH16
5/27/2004 10:36:52 PM
This is not a bug. Flash is functioning properly. The problem is that == is
not designed to compare two date objects. In the case of objects, flash
compares "by reference", which means that if they aren't actually pointing to
the same exact object in memory, then it will return false. What you can do
instead is convert the dates to strings and then use ==, because == will
compare strings fine. Alternately, you could compare each individual part of
the date individually as integers. IM me if you want any more explanation.
Re: problem comparing equality of dates-is this a bug AJH16
5/27/2004 10:37:13 PM
This is not a bug. Flash is functioning properly. The problem is that == is
not designed to compare two date objects. In the case of objects, flash
compares "by reference", which means that if they aren't actually pointing to
the same exact object in memory, then it will return false. What you can do
instead is convert the dates to strings and then use ==, because == will
compare strings fine. Alternately, you could compare each individual part of
the date individually as integers. IM me if you want any more explanation.
Re: problem comparing equality of dates-is this a bug Jack.
5/27/2004 11:24:28 PM
split the date objects to arrays and compare the arrays,

d = new Date(2004, 3, 17);
d1 = d.toString();
d2 = d1.split(""); trace(d2);

e = new Date(2004, 4, 17);
e1 = e.toString();
e2 = e1.split(""); trace(e2);


for(var iv=0; iv!=d2.length; iv++){
if(d2[iv] == e2[iv]){
trace(d2[iv]+" equals "+e2[iv]);
} else {
trace(d2[iv]+" not equal to "+e2[iv]);
}
}

hth
AddThis Social Bookmark Button