2fas2c
Posts: 0
Joined: Mon Dec 16, 2013 11:43 pm

Nullable datetime value

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

Igor
Posts: 0
Joined: Tue Apr 02, 2013 12:05 pm

Nullable datetime value

Hello,

This topic should help : https://getsatisfaction.com/apperyio/...

2fas2c
Posts: 0
Joined: Mon Dec 16, 2013 11:43 pm

Nullable datetime value

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.

Igor
Posts: 0
Joined: Tue Apr 02, 2013 12:05 pm

Nullable datetime value

Lets try to add next code on your mapping field -"Add JS":
pre
code
return "&quot
/code
/pre

2fas2c
Posts: 0
Joined: Mon Dec 16, 2013 11:43 pm

Nullable datetime value

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 "";
}

Igor
Posts: 0
Joined: Tue Apr 02, 2013 12:05 pm

Nullable datetime value

Lets try this code:

pre
code
value = value.replace(/\s/gi, '');
if (value == "") {
return "&quot
} 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

2fas2c
Posts: 0
Joined: Mon Dec 16, 2013 11:43 pm

Nullable datetime value

That solved it. Thanks

Return to “Issues”