I need to extract the DATE for max and min NDVI values in a MODIS NDVI time series. i think I am able to extract the date for max but I have problems with the minimum.

// turn image collection into an array
var array = NDVI.toArray()

// sort array by the first band, keeping other bands
var axes = { image:0, band:1 }
var sort = array.arraySlice(axes.band, 0, 1);  // select bands from index 0 to 1 (NDVI)
var sorted = array.arraySort(sort);

// take the first image only (MAX NDVI)
var length = sorted.arrayLength(axes.image)
var values = sorted.arraySlice(axes.image, length.subtract(1), length);

// convert back to an image  
var max = values.arrayProject([axes.band]).arrayFlatten([['ndvi', 'time']])

// get the max band
var ndviMax = max.select(0) // ndvi max
var time = max.select(1) // get day

This is the link to the code https://code.earthengine.google.com/29618e626ddc93d7d6a6d00103518c6e

Any help/suggestion?

2 Answers 2


You can get the minimum values similar to how you got the max values, but instead you'll need the first position to use arraySlice.

// for the max value sorted
var valuesMax = sorted.arraySlice(axes.image, length.subtract(1), length);
// for the min value sorted
var valuesMin = sorted.arraySlice(axes.image, 0, 1);

Then you can continue with the script similar as you did with the max values.

Here you can find a link to the full script.


You can also get the min & max date with the function aggregate_min() & aggregate_max() on the image collection.


ImageCollection.aggregate_min('system:time_start') & ImageCollection.aggregate_max('system:time_start') 

Your Answer

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

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