Date Format search

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

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

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

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

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

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.

Thanks, that worked well

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:

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

Hi Rochard, try with:

..
.....
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) explain us “why it did not work your way?” :wink:

Tried that, thanks but still getting same damn error!

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.

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

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

this works fine:

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…

arghhh.. :evil: 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: