ee.Date.advance

Create a new Date by adding the specified units to the given Date.

UsageReturns
Date.advance(delta, unit, timeZone)Date
ArgumentTypeDetails
this: dateDate
deltaFloat
unitStringOne of 'year', 'month' 'week', 'day', 'hour', 'minute', or 'second'.
timeZoneString, default: nullThe time zone (e.g., 'America/Los_Angeles'); defaults to UTC.

Examples

Code Editor (JavaScript)

// Defines a base date/time for the following examples.
var BASE_DATE = ee.Date('2020-7-1T13:00', 'UTC');
print(BASE_DATE, 'The base date/time');

// Demonstrates basic usage.
print(BASE_DATE.advance(1, 'week'), '+1 week');
print(BASE_DATE.advance(2, 'years'), '+2 years');

// Demonstrates that negative delta moves back in time.
print(BASE_DATE.advance(-1, 'second'), '-1 second');

Python setup

See the Python Environment page for information on the Python API and using geemap for interactive development.

import ee
import geemap.core as geemap

Colab (Python)

# Defines a base date/time for the following examples.
BASE_DATE = ee.Date('2020-01-01T00:00', 'UTC')
display('The base date/time', BASE_DATE)

# Demonstrates basic usage.
display('+1 week', BASE_DATE.advance(1, 'week'))
display('+2 years', BASE_DATE.advance(2, 'years'))

# Demonstrates that negative delta moves back in time.
display('-1 second', BASE_DATE.advance(-1, 'second'))