# Date Format search

**URL:** <https://forum.servoy.com/t/date-format-search/3245>\
**Category:** Classic Servoy\
**Created:** [December 8, 2004, 3:19pm UTC](https://forum.servoy.com/t/date-format-search/3245 "2004-12-08T15:19:36Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![ebrandt](https://avatars.discourse-cdn.com/v4/letter/e/96bed5/32.png) [@ebrandt](https://forum.servoy.com/u/ebrandt)\
**Post date:** [December 8, 2004, 3:19pm UTC](https://forum.servoy.com/t/date-format-search/3245/1 "2004-12-08T15:19:36Z")

</div>

I created the following method to use 2 global text fields to search a date range. When I run the method I get an error saying the ‘set.Hours is not a function’

var d1 = globals.Text13  
d1.setHours(00)  
d1.setMinutes(00)  
d1.setSeconds(00)  
var df1 = utils.dateFormat(d1, ‘MM-dd-yyyy hh:mm:ss’)

var d2 = globals.Text14  
d1.setHours(00)  
d1.setMinutes(00)  
d1.setSeconds(00)  
var df2 = utils.dateFormat(d2, ‘MM-dd-yyyy hh:mm:ss’)

controller.find()  
shipping\_date\_returned = df1+ ‘…’ + df2 + ‘|MM-dd-yyyy hh:mm:ss’  
controller.search()

Any Ideas what I am missing?

Thanks,  
Erich

---

<div class="post-metadata">

**Author:** ![ebrandt](https://avatars.discourse-cdn.com/v4/letter/e/96bed5/32.png) [@ebrandt](https://forum.servoy.com/u/ebrandt)\
**Post date:** [December 8, 2004, 3:22pm UTC](https://forum.servoy.com/t/date-format-search/3245/2 "2004-12-08T15:22:28Z")

</div>

‘setHours is not a function’ Sorry, that is the correct error dialog

---

<div class="post-metadata">

**Author:** ![automazione](https://avatars.discourse-cdn.com/v4/letter/a/8797f3/32.png) [@automazione](https://forum.servoy.com/u/automazione)\
**Post date:** [December 8, 2004, 3:45pm UTC](https://forum.servoy.com/t/date-format-search/3245/3 "2004-12-08T15:45:27Z")

</div>

Search with dates has been covered other times on this forum, for example have a look to:  
[http://forum.servoy.com/viewtopic.php?t=1349](http://forum.servoy.com/viewtopic.php?t=1349)

I think the problem with your setHours() is that d1 and d2 are not dates but text strings.

---

<div class="post-metadata">

**Author:** ![maarten](https://avatars.discourse-cdn.com/v4/letter/m/ecccb3/32.png) [@maarten](https://forum.servoy.com/u/maarten)\
**Post date:** [December 8, 2004, 3:46pm UTC](https://forum.servoy.com/t/date-format-search/3245/4 "2004-12-08T15:46:20Z")

</div>

Maybe d1 is not a date object.  
What’s the type of globals.Text13 (text, nr date et…?)

---

<div class="post-metadata">

**Author:** ![ebrandt](https://avatars.discourse-cdn.com/v4/letter/e/96bed5/32.png) [@ebrandt](https://forum.servoy.com/u/ebrandt)\
**Post date:** [December 8, 2004, 3:52pm UTC](https://forum.servoy.com/t/date-format-search/3245/5 "2004-12-08T15:52:05Z")

</div>

That must be my problem, I used a global text field, not a global date field, because i thought that the output was a text string.

---

<div class="post-metadata">

**Author:** ![ebrandt](https://avatars.discourse-cdn.com/v4/letter/e/96bed5/32.png) [@ebrandt](https://forum.servoy.com/u/ebrandt)\
**Post date:** [December 8, 2004, 3:54pm UTC](https://forum.servoy.com/t/date-format-search/3245/6 "2004-12-08T15:54:59Z")

</div>

Thanks, that worked well

---

<div class="post-metadata">

**Author:** ![rochard](https://avatars.discourse-cdn.com/v4/letter/r/e9c0ed/32.png) [@rochard](https://forum.servoy.com/u/rochard)\
**Post date:** [February 14, 2005, 7:31pm UTC](https://forum.servoy.com/t/date-format-search/3245/7 "2005-02-14T19:31:22Z")

</div>

```auto
forms.Allottments.controller.show();

var startdate = globals.arrivalDate 
startdate.setHours(00) 
startdate.setMinutes(00) 
startdate.setSeconds(00) 
var thestart = utils.dateFormat(startdate, 'MM-dd-yyyy HH:mm:ss') 

var enddate = globals.arrivalDate2 
enddate.setHours(00) 
enddate.setMinutes(00) 
enddate.setSeconds(00) 
var theend = utils.dateFormat(enddate, 'MM-dd-yyyy HH:mm:ss') 

var hotel = globals.searchHotelInt

forms.Allottments.controller.find;

forms.Allottments.allocatedate = thestart + '...' + theend+ '|MM-dd-yyyy HH:mm:ss'; 
forms.Allottments.locationid = hotel;

forms.Allottments.controller.search;

```

Both my global fields are datetime fields. The allocatedate field is formatted as MM-dd-yyyy but everytime I run this search I get the following error:

```auto
Setting dataprovider with name 'allocatedate' / type 'DATETIME' with value of wrong type 02-08-2005 00:00:00...02-15-2005 00:00:00|MM-dd-yyyy HH:mm:ss

```

I must be missing something very obvious!

TIA

---

<div class="post-metadata">

**Author:** ![automazione](https://avatars.discourse-cdn.com/v4/letter/a/8797f3/32.png) [@automazione](https://forum.servoy.com/u/automazione)\
**Post date:** [February 15, 2005, 3:19pm UTC](https://forum.servoy.com/t/date-format-search/3245/8 "2005-02-15T15:19:17Z")

</div>

Hi Rochard, try with:

```auto
..
.....
var xx = thestart + '...' + theend+ '|MM-dd-yyyy HH:mm:ss'; 
forms.Allottments.controller.find;
forms.Allottments.allocatedate = xx;
forms.Allottments.locationid = hotel;
forms.Allottments.controller.search;
.....
..

```

… then… let us wait that some guru ![8)]( "Cool") explain us “why it did not work your way?” ![:wink:]( "Wink")

---

<div class="post-metadata">

**Author:** ![rochard](https://avatars.discourse-cdn.com/v4/letter/r/e9c0ed/32.png) [@rochard](https://forum.servoy.com/u/rochard)\
**Post date:** [February 16, 2005, 7:49pm UTC](https://forum.servoy.com/t/date-format-search/3245/9 "2005-02-16T19:49:41Z")

</div>

Tried that, thanks but still getting same damn error!

```auto
Setting dataprovider with name 'allocatedate' / type 'DATETIME' with value of wrong type 06-01-2005 00:00:00...07-13-2005 00:00:00|MM-dd-yyyy HH:mm:ss

```

have tried formatting the allocatedate field numerous different ways with no difference.

---

<div class="post-metadata">

**Author:** ![maarten](https://avatars.discourse-cdn.com/v4/letter/m/ecccb3/32.png) [@maarten](https://forum.servoy.com/u/maarten)\
**Post date:** [February 17, 2005, 9:28pm UTC](https://forum.servoy.com/t/date-format-search/3245/10 "2005-02-17T21:28:30Z")

</div>

looks like a bug to me.  
I’ve reported to dev team.

---

<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:** [February 17, 2005, 10:25pm UTC](https://forum.servoy.com/t/date-format-search/3245/11 "2005-02-17T22:25:04Z")

</div>

that is no bug.  
That is a programming error in the script.

this works fine:

```auto
forms.Allottments.controller.find();
forms.Allottments.allocatedate = thestart + '...' + theend+ '|MM-dd-yyyy HH:mm:ss';
forms.Allottments.locationid = hotel;
forms.Allottments.controller.search();

```

you have to call the method. Not just ‘declare’ it…

---

<div class="post-metadata">

**Author:** ![maarten](https://avatars.discourse-cdn.com/v4/letter/m/ecccb3/32.png) [@maarten](https://forum.servoy.com/u/maarten)\
**Post date:** [February 17, 2005, 10:56pm UTC](https://forum.servoy.com/t/date-format-search/3245/12 "2005-02-17T22:56:22Z")

</div>

arghhh.. ![:evil:]( "Evil or Very Mad") TIP TIP TIP \>\>\> use CODE COMPLETION!!!

1. put your cursor in the script editor
2. type “c”
3. hit Ctrl+Spacebar
4. hit Enter
5. hit “f”
6. hit Enter

..and don’t copy paste bad code ![:oops:]( "Embarassed")
