# typeof dateField gives JavaScript Error

**URL:** <https://forum.servoy.com/t/typeof-datefield-gives-javascript-error/10849>\
**Category:** Classic Servoy\
**Created:** [July 1, 2009, 10:08am UTC](https://forum.servoy.com/t/typeof-datefield-gives-javascript-error/10849 "2009-07-01T10:08:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [July 1, 2009, 10:08am UTC](https://forum.servoy.com/t/typeof-datefield-gives-javascript-error/10849/1 "2009-07-01T10:08:42Z")

</div>

When I use the following syntax:

```auto
typeof myDateField

```

I get the following (uncatchable) error:

```auto
org.mozilla.javascript.EvaluatorException: Invalid JavaScript value of type java.util.Date

```

So it seems the value of a datefield is not a JavaScript date but a Java date.  
Is there anyway to check if a value is a Java date within JavaScript ?

Servoy 3.5.10

---

<div class="post-metadata">

**Author:** ![pbakker](https://avatars.discourse-cdn.com/v4/letter/p/a4c791/32.png) [@pbakker](https://forum.servoy.com/u/pbakker)\
**Post date:** [July 1, 2009, 10:45am UTC](https://forum.servoy.com/t/typeof-datefield-gives-javascript-error/10849/2 "2009-07-01T10:45:58Z")

</div>

This is already fixed in Servoy 4.x

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [July 1, 2009, 10:51am UTC](https://forum.servoy.com/t/typeof-datefield-gives-javascript-error/10849/3 "2009-07-01T10:51:10Z")

</div>

Any workaround for now ? I can’t upgrade a live system yet but I can push a quickfix (when possible).

---

<div class="post-metadata">

**Author:** ![patrick](https://avatars.discourse-cdn.com/v4/letter/p/b2d939/32.png) [@patrick](https://forum.servoy.com/u/patrick)\
**Post date:** [July 1, 2009, 12:13pm UTC](https://forum.servoy.com/t/typeof-datefield-gives-javascript-error/10849/4 "2009-07-01T12:13:53Z")

</div>

instanceof Date

should work.

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [July 1, 2009, 12:17pm UTC](https://forum.servoy.com/t/typeof-datefield-gives-javascript-error/10849/5 "2009-07-01T12:17:52Z")

</div>

what do you expect typeof datefield gives you back?  
“date” ?

that it doesnt do it will return “object” so you dont get very far. (even null will return “object”)

If you really want to know that it is a date you can do this:

if (datefield instanceof Date)  
{  
// xxx  
}

Argghh patrick was just before me…

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [July 1, 2009, 1:09pm UTC](https://forum.servoy.com/t/typeof-datefield-gives-javascript-error/10849/6 "2009-07-01T13:09:39Z")

</div>

> jcompagner:  
> what do you expect typeof datefield gives you back?

I used the example of a datefield, but it could also be a text field with a date or something. In my code I need to know what type of value it holds and process it accordingly.  
All this is part of a workaround in 2.2.x to make sure a search in related tables (1 or 2 deep) doesn’t result in double parent records. I.e. I had to reproduce Servoy’s search functionality.

Anyway, thanks Patrick and Johan! Got the fix working.

Edit: I meant version 2.2.x, not 3.x
