Select to view content in your preferred language

editing a field of type date

1728
1
02-14-2011 09:53 AM
GabrielCarballo
Deactivated User
I am modifying the FeatureLayerEditingSample code to work to edit my own point layer. I am able to save my edits successfully as long as there are no fields typed as "Date" on my feature class. What is the correct method to save a date?

In the sample, the date field is of type string and gets assigned using this line:
[self.feature.attributes setValue:[self.dateFormat stringFromDate:self.date] forKey:@"req_date"];

Thanks
0 Kudos
1 Reply
ClayTinnell
Occasional Contributor
One way is to work with the date is in a unit equal to the number of milliseconds since January 1 1970.  In order to accomplish this, you can return the number of seconds since 1970 using NSTimeInterval.

Example:
[self.mappedField.attributes setValue:[NSNumber numberWithDouble:[self.tempDate.date timeIntervalSince1970] * 1000.00] forKey:PLANTDATE];

And this to retrieve a date:
double timeInterval = [[self.mappedField.attributes objectForKey:PLANTDATE] doubleValue] / 1000.00;
self.tempDate = [NSDate dateWithTimeIntervalSince1970:timeInterval];
0 Kudos