1

I have a featureCollection with the dates for 2021. I would like to do a date conversion for this featureCollection to get the same dates in 2017. I have written the function above but it returns the error. How can I solve this?

//Date conversion
print(swarms)

//Converting data parameter 

function epoch2date(feature){
  var epoch = feature.get('STARTDATE');
  var date = ee.Date(epoch).format('YYYY-MM-dd');
  return feature.set('date', date);
}

var swarmDates = swarms.map(epoch2date);
print(swarmDates)


//Compute dates in 2017
function dates(feature){
  var date = swarmDates.get('date');
  var newDate = ee.Date(date).advance(-4, 'year').format('YYYY-MM-dd');
  return feature.set('newDate', newDate)
}

var dates2017 = swarms.map(dates);

print(dates2017)

The link to the code to is;https://code.earthengine.google.com/098d3ae0185833f573d8f3e372fc5160

2
  • What is the erro you get?
    – JonasV
    Oct 20, 2021 at 7:48
  • @JonasV this is the error I am getting FeatureCollection (Error) Date: Parameter 'value' is required.
    – Shiraz
    Oct 20, 2021 at 8:02

1 Answer 1

1

You have two typos in your code. In the function dates your are mistakenly calling swarmDates instead of feature. And for dates2017 you have to call map on swarmDates instead of swarms

//Compute dates in 2017
function dates(feature){
  var date = feature.get('date');
  var newDate = ee.Date(date).advance(-4, 'year').format('YYYY-MM-dd');
  return feature.set('newDate', newDate)
}

var dates2017 = swarmsDates.map(dates);

print(dates2017) 
1
  • thanks for pointing out the typos in the code. Now it works perfectly. Much appreciated!
    – Shiraz
    Oct 20, 2021 at 8:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.