Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #24055

Re: Date false

From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.javascript
Subject Re: Date false
Date 2014-05-09 10:46 +0200
Organization PointedEars Software (PES)
Message-ID <2257287.d1qsfXZ9WQ@PointedEars.de> (permalink)
References <1JidnUNwV7viyvHOnZ2dnUVZ_t6dnZ2d@westnet.com.au>

Show all headers | View raw


Andrew Poulos wrote:

> I'm use JScript with ASP to read a db
> 
> // if there's no error, d can either be a date or 0 (zero)

No.

> var d = e = rs("ExpiryDay").value;
> 
> Then I use it in an if statement
> 
> if (d) {
>    // 'do something'
> }
> 
> even when
>    window.alert(d +" + "+ (typeof d));
> displays
>    Thu May 14 00:00:00 UTC 1000 2015 + date
> 'do something' never happens.
> 
> I'm confused. Can a date be false?

rs("ExpiryDay").value does not store a reference to a Date instance, but to 
a host object.  Otherwise the “typeof” operation would have resulted in 
"object", not "date".

The return value of rs("ExpiryDay") probably also refers to a host object, 
and using a host object or a host object’s property in a type-converting 
test can be error-prone.

Using the (binary) “+” operator with at least one string value as operand 
converts the other, non-string operand to the String type, and concatenates 
the resulting values.  "Thu May 14 00:00:00 UTC 1000 2015" indicates “not a 
proper DateTime value in the database”.  It makes sense that this is type-
converted to “false”.

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Date false Andrew Poulos <ap_prog@hotmail.com> - 2014-05-09 14:18 +1000
  Re: Date false Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-05-09 10:46 +0200
  Re: Date false "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-05-09 10:58 +0200
  Re: Date false Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-05-09 11:01 +0200
  Re: Date false Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2014-05-09 17:27 -0300
    Re: Date false Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2014-05-09 17:32 -0300
    Re: Date false Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-05-10 10:36 +0200
  Re: Date false Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2014-05-09 18:05 -0300

csiph-web