As part of a series of select queries I want to be able to test whether a field is a date. This server-side code returns false:
function main () { var isthisadate = rbv_api.selectQuery('SELECT field1#value FROM object1', 1); return isthisadate[0][0] instanceof Date; } main();
And this code returns [object JavaObject]:
function main () { var isthisadate = rbv_api.selectQuery('SELECT field1#value FROM object1', 1); var toString = Object.prototype.toString; return toString.call(isthisadate[0][0]); } main();
So is the result of the select query not a JS date object? How do I test whether the data type of the field is a date?
Thank you,
Greg
Hi Greg,
The return type of select query will be array of strings irrespective of the data type being used in object column.
Please use rbv_api.formatDate(arg1, pattern) function which will format the date according the format specified in the parameter. It will return a valid date , if arg1 is a valid date otherwise it will return null.
Example:
var date=rbv_api.selectQuery("SELECT dateField FROM SampleObject",1);
var formatDate=rbv_api.formatDate(date[0][0], "yyyy-MM-dd HH:mm:ss");
if(formatDate){
rbv_api.println("valid date");
}else
{
rbv_api.println("invalid date");
}
Regards,
Shiva
Hi Greg,
The return type of select query will be array of strings irrespective of the data type being used in object column.
Please use rbv_api.formatDate(arg1, pattern) function which will format the date according the format specified in the parameter. It will return a valid date , if arg1 is a valid date otherwise it will return null.
Example:
var date=rbv_api.selectQuery("SELECT dateField FROM SampleObject",1);
var formatDate=rbv_api.formatDate(date[0][0], "yyyy-MM-dd HH:mm:ss");
if(formatDate){
rbv_api.println("valid date");
}else
{
rbv_api.println("invalid date");
}
Regards,
Shiva
Thank you very much, Shiva.
Greg