I am learning GIS using Google Earth Engine.

When learning "Changing detection" I have this code:

// Define the area of interest
var geometry = ee.Geometry.Polygon([[
 [76.37639666685044, 11.766523239445169],
 [76.37639666685044, 11.519036946599561],
 [76.78426409849106, 11.519036946599561],
 [76.78426409849106, 11.766523239445169]
var fireStart = ee.Date('2019-02-20');
var fireEnd = ee.Date('2019-02-25');
Map.centerObject(geometry, 10)
var s2 = ee.ImageCollection("COPERNICUS/S2")
// Write a function for Cloud masking
function maskS2clouds(image) {
 var qa = image.select('QA60')
 var cloudBitMask = 1 << 10;
 var cirrusBitMask = 1 << 11;
 var mask = qa.bitwiseAnd(cloudBitMask).eq(0).and(
 return image.updateMask(mask)//.divide(10000)
 .copyProperties(image, ["system:time_start"])
// Apply filters and cloud mask
var filtered = s2
// Create Before and After composites
var before = filtered
 fireStart.advance(-2, 'month'), fireStart))
var after = filtered
 fireEnd, fireEnd.advance(1, 'month')))

I don't understand what is the mean of "fireEnd.advance(1, 'month')" and "fireStart.advance(-2, 'month') "line.

What does it mean by "-2" or "1"?

  • This is probably not related to GIS question. Rather it is a programming question and post it to Stackoverflow. Jan 11, 2023 at 9:35
  • 2
    I've never used GEE, but first search with Bing on "gee date .advance" gave this: developers.google.com/earth-engine/apidocs/ee-date-advance
    – TomazicM
    Jan 11, 2023 at 9:36
  • 1
    With -2 you're advancing backwards :-). You get a new date two months before the one you're calling advance() on. With 1 you get next month. Jan 11, 2023 at 9:48

1 Answer 1


Its a time Shift!

In your Code:

fireStart.advance(-2, 'month')

fireStart is a Date. With advance you can shift the Date. The examples output ist the day just 2 Months before fireStart.

Just watch here for more Info.

For Future EarthEngine Questions you should ask Google or look directly into the API Reference. Just search for "EarthEngine" + Keyword (e.g. .advance)

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.