Re: dd/mm/yyyy Date Compare Problem
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

Re: dd/mm/yyyy Date Compare Problem

From: Thomas 'PointedEars' Lahn <PointedEars@web.de>
Date: Fri Apr 28 2006 - 20:54:47 CEST

jshanman wrote:

> Steve Kostecke wrote:
>> jshanman wrote:
>> > Assimalyst wrote:
>> >> [...]
>> >> var useDodDate = new Date(arrDodDate[2], arrDodDate[1],
>> >> arrDodDate[0]); // yyyy/mm/dd
>> >> [...]
>> >> var useDobDate = new Date(arrDobDate[2], arrDobDate[1],
>> >> arrDobDate[0]); // yyyy/mm/dd
>> >>
>> >> if (useDobDate < useDodDate)
>> >> {
>> >> args.IsValid = true;
>> >> }
>> >> else
>> >> {
>> >> args.IsValid = false;
>> >> }
>> >> }
>> >>
>> >> But this creates errors on the page when it runs and always fails the
>> >> custom validator.
>> >> [...]
>> > Your function works fine for me when called correctly: (IE6 & Firefox
>> > 1.5)
>> Why doesn't it work in NN 4 ?
>
> Matt Kruse is right, the proper way would actually be using the
> .valueOf() (or getTime() method of the date object.

No, against it would not be any more or less proper than without
calling .valueOf() or .getTime(). Automatic type conversion does the job,
see ECMAScript 3 Edition 3 Final, section 11.8 (one wonders how many times
Matt must be told this). And it works perfectly fine in Mozilla/4.8 [en]
(X11; U; Linux 2.6.15.6-20060314.201202+0100 i686).

However,

  args.isValid = (useDobDate < useDodDate);

is more efficient.

PointedEars

-- 
When the power of love overcomes the love
of power, the world will know peace.
  -- Jimi Hendrix
Received on Mon May 1 05:26:01 2006