Page 1 of 1

Search by date using showInputDialog

PostPosted: Fri Apr 08, 2005 11:19 am
by Thunder
Hi all

I want to search a datetime field for all records <= a particular date. To try this, I did this in my method attached to a button:

var typedInput = plugins.dialogs.showInputDialog('Specify a date','up to and including date\n(use date in 25.12.2005 format)');
controller.find()
date_of_purchase = "<= typedInput"
controller.search()

The sybase datetime field "date_of_purchase" is formatted dd.MM.yyyy. My search does not work, it just finds all records - even though there are many records who's purchase date is after what I specify in the dialog.

I have tried date_of_purchase = "<=" + typedInput; - no joy. It still finds all 11 records (only one is before the date that I specify)

What am I doing wrong???

Thanks

Bevil[/i]

PostPosted: Fri Apr 08, 2005 1:59 pm
by Harry Catharell
Hi Bevil,

You were right to move the input variable out of the text string for the operator but you also need to tell the field what format your date is in as follows :
Code: Select all
date_of_purchase = "<= " + typedInput + '|dd-MM-yyyy';

so your method becomes:
Code: Select all
var typedInput = plugins.dialogs.showInputDialog('Specify a date','up to and including date\n(use date in 25-12-2005 format)');
controller.find() ;
date_of_purchase = "<= " + typedInput + '|dd-MM-yyyy';
controller.search()


See this thread which will certainly help:
http://forum.servoy.com/viewtopic.php?t=1349


Cheers
Harry

PostPosted: Fri Apr 08, 2005 2:03 pm
by Thunder
thanks to the indefatigable help of JA, I was able to turn my brains back on and fix it. To future readers of this post, to save you being subjected to JA's SUD errors and etc., the solution was to join the field to the string (in my case |dd.MM.yyyy) with a + and put the string in quotes. i.e. date_of_purchase = '<=' + typedInput + '|dd.MM.yyyy'

PostPosted: Fri Apr 08, 2005 2:06 pm
by Thunder
Thanks Harry

I was able to get it sorted in exactly the way you said. Thanks..

Bevil