setting datetime by method causes an error

Hi,

I would like to set a specific date and time to the column “start_datetime” of type DATETIME by method, but I get the error:

Setting dataprovider with name ‘start_datetime’, type ‘DATETIME’ with value of wrong type 2012-01-19 01:00:00
Wrapped java.lang.IllegalArgumentException: Setting dataprovider with name ‘start_datetime’, type ‘DATETIME’ with value of wrong type 2012-01-19 01:00:00

I can set the datetime manually in a calendar field on a form without errors. if I take a look on the table data in Servoy Developer, the format of the “start_datetime” is “2012-01-19 01:00:00:000”. In the table view of pgAdmin, the format is “2012-01-19 01:00:00”.
I have tried both formats setting the datetime into the dataprovider by method without success. How should I set a datetime right that it works?

Servoy 6.0.4
PostgreSQL 9.1.2

Regards

Hi Thomas,

You say you set the date and time by method. Can you show us some code ?
it sounds to me you are passing a string instead of a date object.

Hi Robert,

I think you are right! That’s my code:

var _date = utils.dateFormat(new Date(),'yyyy-MM-dd');
start_datetime = _date + "01:00:00";

How can I do it in a date object?

Regards

Hi Thomas,

You can use the following code:

var _d = new Date();
start_datetime = new Date(_d.getFullYear(), _d.getMonth(), _d.getDate(), 1, 0, 0); 

// to also (re)set the milliseconds use this
// start_datetime = new Date(_d.getFullYear(), _d.getMonth(), _d.getDate(), 1, 0, 0, 0);

Thank you Robert,

it works very well!