Page 1 of 1
Nullable datetime value
Posted: Mon Mar 03, 2014 12:02 am
by 2fas2c
I have DOB field in my collection which is of Date data type. It is a nullable field. Whenever I try to insert with a null value, i get an exception
{"code":"DBSU230","description":"Incorrect date format: 'NaN-NaN-NaN'. Correct format is 'yyyy-mm-dd'."}
How do I resolve it?
Thanks
Nullable datetime value
Posted: Mon Mar 03, 2014 12:46 am
by Igor
Nullable datetime value
Posted: Mon Mar 03, 2014 1:37 am
by 2fas2c
I am able to save and retrieve date values fine into the database. My only issue is with storing null values into the date field. So I am not sure how this will solve the issue.
Nullable datetime value
Posted: Mon Mar 03, 2014 2:52 am
by Igor
Lets try to add next code on your mapping field -"Add JS":
pre
code
return ""
/code
/pre
Nullable datetime value
Posted: Mon Mar 03, 2014 3:32 am
by 2fas2c
I did. Same error.
Here is the code I have in "Edit JS" for the DOB field:
if (value !== null) {
var dob = new Date(value);
Code: Select all
var day = dob.getDate();
var month = dob.getMonth() + 1;
var year = dob.getFullYear();
formattedDate = year + '-' + month + '-' + day;
return formattedDate;
}
else {
return "";
}
Nullable datetime value
Posted: Mon Mar 03, 2014 4:05 am
by Igor
Lets try this code:
pre
code
value = value.replace(/\s/gi, '');
if (value == "") {
return ""
} else {
var dob = new Date(value);
Code: Select all
var day = dob.getDate();
var month = dob.getMonth() + 1;
var year = dob.getFullYear();
formattedDate = year + '-' + month + '-' + day;
return formattedDate;
}
/code
/pre
Nullable datetime value
Posted: Mon Mar 03, 2014 4:32 am
by 2fas2c