problems saving datetime to SDE via applyedits

1679
7
Jump to solution
02-06-2014 07:25 AM
JustinClowes
New Contributor II
I'm trying to create a new feature using featureLayer.applyEdits.
I pass in the geometry and attributes and this is saved to the database correctly.
When I try and save a datetime attribute I get the error : "Error saving new find : Unable to complete operation".

Does anyone know what format the datetime needs to be in?

I am using ArcGIS Server v10 with SQL Server 2008.
Thanks. See my code below:

var datetime = dojo.date.locale.parse("07/02/2014 13:54",
        {
                datePattern:"dd/MM/yyyy",
                timePattern:"HH:mm"
        }
);

var attr = {
"DATE_TIME_J" : datetime
};

var ng = new esri.Graphic(Point, null, attr, null);
featureLayer.applyEdits([ng], null, null, ........
0 Kudos
1 Solution

Accepted Solutions
martinschmoll
New Contributor III
I use the .valueOf() function to pass the current date into Oracle via applyEdits() on a FeatureService:

... "DATETIME": new Date().valueOf(); ...

View solution in original post

0 Kudos
7 Replies
martinschmoll
New Contributor III
I use the .valueOf() function to pass the current date into Oracle via applyEdits() on a FeatureService:

... "DATETIME": new Date().valueOf(); ...
0 Kudos
JeffPace
MVP Alum
I'm trying to create a new feature using featureLayer.applyEdits.
I pass in the geometry and attributes and this is saved to the database correctly.
When I try and save a datetime attribute I get the error : "Error saving new find : Unable to complete operation".

Does anyone know what format the datetime needs to be in?

I am using ArcGIS Server v10 with SQL Server 2008.
Thanks. See my code below:

var datetime = dojo.date.locale.parse("07/02/2014 13:54",
        {
                datePattern:"dd/MM/yyyy",
                timePattern:"HH:mm"
        }
);

var attr = {
"DATE_TIME_J" : datetime
};

var ng = new esri.Graphic(Point, null, attr, null);
featureLayer.applyEdits([ng], null, null, ........


if the field you are trying to write to a date field? or a string
0 Kudos
JustinClowes
New Contributor II
thanks, yes I'm trying to write to a datetime field (in SQL Server) and I need to include both the date and the time.
I need to write a specific date + time, not the current date
0 Kudos
martinschmoll
New Contributor III
I need to write a specific date + time, not the current date


I thought it was obvious, but the valueOf() function can be used on any date!  We use Oracle, and this was the solution for us.  So in your example try:

var attr = {
"DATE_TIME_J" : datetime.valueOf()
};
0 Kudos
JeffPace
MVP Alum
mschmoll is is right

By passing datetime, you are actually sending the parsed string to the database

but using valueof(), you are likely sending the actual datetime value
0 Kudos
JustinClowes
New Contributor II
Thanks, that works perfectly with SQL Server too. Problem solved.
0 Kudos
JeffPace
MVP Alum
great to hear! please mark mschmoll's post as the answer by checking the checkmark on his post so he gets credit for it.
0 Kudos