Announcement: All noncommercial projects registered to use Earth Engine beforeApril 15, 2025 mustverify noncommercial eligibility to maintain access. If you have not verified by September 26, 2025, your access may be on hold.

ee.Filter.calendarRange

  • Theee.Filter.calendarRange function returns a filter for timestamps within a calendar field range.

  • Calendar fields like month and day are 1-based, and times are assumed to be in UTC.

  • A wrapping range is supported where the end value is less than the start value.

  • The preferred methods for filtering by whole years and day of year areee.Filter.date andee.Filter.dayOfYear, respectively, due to performance.

Returns a filter that passes if the object's timestamp falls within the given range of a calendar field. Themonth,day_of_year,day_of_month, andday_of_week are 1-based. Times are assumed to be in UTC. Weeks are assumed to begin on Monday as day 1. Ifend <start then this tests forvalue >=start ORvalue <=end, to allow for wrapping.

UsageReturns
ee.Filter.calendarRange(start,end,field)Filter
ArgumentTypeDetails
startIntegerThe start of the desired calendar field, inclusive.
endInteger, default: nullThe end of the desired calendar field, inclusive. Defaults to the same value as start.
fieldString, default: "day_of_year"The calendar field to filter over. Options are: `year`, `month`, `hour`, `minute`, `day_of_year`, `day_of_month`, and `day_of_week`.

Examples

Code Editor (JavaScript)

// A Sentinel-2 surface reflectance image collection intersecting the peak of// Mount Shasta, California, USA.varic=ee.ImageCollection('COPERNICUS/S2_SR').filterBounds(ee.Geometry.Point(-122.196,41.411));print('Images for a month range (June-August)',ic.filter(ee.Filter.calendarRange(6,8,'month')));print('A start value greater than end value is valid (Dec-Feb)',ic.filter(ee.Filter.calendarRange(12,2,'month')));// This example uses the 'year' field value. Note that ee.Filter.date is the// preferred method when filtering by whole years, as it is much faster.print('Images for a year range (2020-2021)',ic.filter(ee.Filter.calendarRange(2020,2021,'year')));// This example uses the 'day_of_year' field value. Note that// ee.Filter.dayOfYear is the preferred method for filtering by DOY.// The ee.Date.getRelative function is used to identify DOY from an ee.Date// object for a representative year. Be mindful of leap years when filtering// by DOY.varstartDoy=ee.Date('2000-06-01').getRelative('day','year');varendDoy=ee.Date('2000-06-15').getRelative('day','year');print('start DOY =',startDoy,'end DOY =',endDoy,'Images for a day-of-year range',ic.filter(ee.Filter.calendarRange(startDoy,endDoy,'day_of_year')));

Python setup

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

importeeimportgeemap.coreasgeemap

Colab (Python)

# A Sentinel-2 surface reflectance image collection intersecting the peak of# Mount Shasta, California, USA.ic=ee.ImageCollection('COPERNICUS/S2_SR').filterBounds(ee.Geometry.Point(-122.196,41.411))display('Images for a month range (June-August):',ic.filter(ee.Filter.calendarRange(6,8,'month')))display('A start value greater than end value is valid (Dec-Feb):',ic.filter(ee.Filter.calendarRange(12,2,'month')).size())# This example uses the 'year' field value. Note that ee.Filter.date is the# preferred method when filtering by whole years, as it is much faster.display('Images for a year range (2020-2021):',ic.filter(ee.Filter.calendarRange(2020,2021,'year')).size())# This example uses the 'day_of_year' field value. Note that# ee.Filter.dayOfYear is the preferred method for filtering by DOY.# The ee.Date.getRelative function is used to identify DOY from an ee.Date# object for a representative year. Be mindful of leap years when filtering# by DOY.start_doy=ee.Date('2000-06-01').getRelative('day','year')end_doy=ee.Date('2000-06-15').getRelative('day','year')display('start DOY =',start_doy,'end DOY =',end_doy)display('Images for a day-of-year range:',ic.filter(ee.Filter.calendarRange(start_doy,end_doy,'day_of_year')))

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2023-10-06 UTC.