I want to have a loop on a date variable in Google Earth Engine, but it hangs and show me nothing when running just below simple code:

var aDate = ee.Date.fromYMD(2015,12,21);
var bDate = ee.Date.fromYMD(2015,12,31);
for(var d = aDate; d < bDate; d.advance(1,'day')){

I tried it in different forms and also via while loop, but it always hangs. Any clue?

  • MSDN help for Date says you need to use 'new' or you get a string rather than a true date object. Could that be the issue? – mkennedy Jul 30 '18 at 17:07
  • Well, I am not much familiar with Javascript. I was just using the code style that I found in Google Earth Engine API and there is no use of 'new' codeword in their API for declaring and using variable of Date type. – Shahriar49 Jul 31 '18 at 0:38

Don't use for-loops for reasons described here and here and here. Do it this way:

var aDate = ee.Date.fromYMD(2015,12,21);
var days = ee.List.sequence(1, 10);
var dates = days.map(function(d) {
  return aDate.advance(d, 'day');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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