I wrote a small script that filters GEE image collection by date that I'm manually change:

var start_date = '2018-11-02'
var end_date = '2018-11-30'

// choose image collection
var ls8 = ee.ImageCollection('LANDSAT/LC08/C01/T1_RT_TOA')
.filterDate(start_date, end_date)

fc is a feature collection. This works fine but I'm looking for a way to change the end_date for today and the start_day for 10 (or some other number) days before today, automatically. So every time I ran the script it looks for images in the last 10 days.

Maybe something like:

var start_date = ee.Date(Now-10)
var end_date = ee.Date(Now)

Is there something like that?

1 Answer 1

var newDate = new Date();
var today = ee.Date(newDate);
var previous = today.advance(-10, 'day');

print(newDate); print(today); print(previous);

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.