ee.Date.getRange
Returns a DateRange covering the unit of the specified type that contains this date, e.g., Date('2013-3-15').getRange('year') returns DateRange('2013-1-1', '2014-1-1').
Usage | Returns | Date.getRange(unit, timeZone) | DateRange |
Argument | Type | Details | this: date | Date | |
unit | String | One of 'year', 'month' 'week', 'day', 'hour', 'minute', or 'second'. |
timeZone | String, default: null | The time zone (e.g., 'America/Los_Angeles'); defaults to UTC. |
Examples
Code Editor (JavaScript)
var date = ee.Date('2021-4-30T07:15:31.24');
print('1-year date range covering input date', date.getRange('year'));
print('1-month date range covering input date', date.getRange('month'));
print('1-week date range covering input date', date.getRange('week'));
print('1-day date range covering input date', date.getRange('day'));
print('1-hour date range covering input date', date.getRange('hour'));
print('1-minute date range covering input date', date.getRange('minute'));
print('1-second date range covering input date', date.getRange('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)
date = ee.Date('2021-4-30T07:15:31.24')
display('1-year date range covering input date:', date.getRange('year'))
display('1-month date range covering input date:', date.getRange('month'))
display('1-week date range covering input date:', date.getRange('week'))
display('1-day date range covering input date:', date.getRange('day'))
display('1-hour date range covering input date:', date.getRange('hour'))
display('1-minute date range covering input date:', date.getRange('minute'))
display('1-second date range covering input date:', date.getRange('second'))
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-13 UTC.
[null,null,["Last updated 2024-07-13 UTC."],[[["`Date.getRange()` returns a `DateRange` object representing the specified time unit (year, month, week, day, hour, minute, or second) that contains the input date."],["The returned `DateRange` spans the entire unit of time, for example, if the input date is March 15, 2013, and the unit is 'year', the returned `DateRange` will be from January 1, 2013, to January 1, 2014."],["You can optionally specify a time zone for the `DateRange`; if not provided, it defaults to UTC."],["This function is useful for creating time-based filters or selecting data within specific time intervals."]]],[]]