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.Date.getFraction

  • TheDate.getFraction() method returns the elapsed fraction of a specified time unit for a given date.

  • The method takes a requiredunit argument (e.g., 'year', 'month', 'day') and an optionaltimeZone argument.

  • The output is a float value between 0 and 1, representing the fraction of the unit that has passed.

Returns this date's elapsed fraction of the specified unit (between 0 and 1).

UsageReturns
Date.getFraction(unit,timeZone)Float
ArgumentTypeDetails
this:dateDate
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)

vardate=ee.Date('2021-4-30T07:15:31.24');print('Elapsed fraction of a year',date.getFraction('year'));print('Elapsed fraction of a month',date.getFraction('month'));print('Elapsed fraction of a week',date.getFraction('week'));print('Elapsed fraction of a day',date.getFraction('day'));print('Elapsed fraction of an hour',date.getFraction('hour'));print('Elapsed fraction of a minute',date.getFraction('minute'));print('Elapsed fraction of a second',date.getFraction('second'));

Python setup

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

importeeimportgeemap.coreasgeemap

Colab (Python)

date=ee.Date('2021-4-30T07:15:31.24')display('Elapsed fraction of a year:',date.getFraction('year'))display('Elapsed fraction of a month:',date.getFraction('month'))display('Elapsed fraction of a week:',date.getFraction('week'))display('Elapsed fraction of a day:',date.getFraction('day'))display('Elapsed fraction of an hour:',date.getFraction('hour'))display('Elapsed fraction of a minute:',date.getFraction('minute'))display('Elapsed fraction of a second:',date.getFraction('second'))

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 2025-06-23 UTC.