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'))