# xarray.core.accessor_dt.DatetimeAccessor

### *class* xarray.core.accessor_dt.DatetimeAccessor(obj)[[source]](https://github.com/pydata/xarray/blob/main/xarray/core/accessor_dt.py#L321-L603)

Access datetime fields for DataArrays with datetime-like dtypes.

Fields can be accessed through the .dt attribute
for applicable DataArrays.

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('40b34892-5e50-43f7-b7f9-d40498c50e4b','d5c601ce-cf07-452a-93a9-ec20578d6e87','5e034231-8d35-4366-b749-81bb24aeeb24','../lite/tree/../notebooks/index.html?path=cecb2f63_92ef_4719_a5fa_4c475b27c157.ipynb','None')">Try it in your browser!</button></div>
```pycon
>>> dates = pd.date_range(start="2000/01/01", freq="D", periods=10)
>>> ts = xr.DataArray(dates, dims=("time"))
>>> ts
<xarray.DataArray (time: 10)> Size: 80B
array(['2000-01-01T00:00:00.000000', '2000-01-02T00:00:00.000000',
       '2000-01-03T00:00:00.000000', '2000-01-04T00:00:00.000000',
       '2000-01-05T00:00:00.000000', '2000-01-06T00:00:00.000000',
       '2000-01-07T00:00:00.000000', '2000-01-08T00:00:00.000000',
       '2000-01-09T00:00:00.000000', '2000-01-10T00:00:00.000000'],
      dtype='datetime64[us]')
Coordinates:
  * time     (time) datetime64[us] 80B 2000-01-01 2000-01-02 ... 2000-01-10
>>> ts.dt
<xarray.core.accessor_dt.DatetimeAccessor object at 0x...>
>>> ts.dt.day_of_year
<xarray.DataArray 'day_of_year' (time: 10)> Size: 80B
array([ 1,  2,  3,  4,  5,  6,  7,  8,  9, 10])
Coordinates:
  * time     (time) datetime64[us] 80B 2000-01-01 2000-01-02 ... 2000-01-10
>>> ts.dt.quarter
<xarray.DataArray 'quarter' (time: 10)> Size: 80B
array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
Coordinates:
  * time     (time) datetime64[us] 80B 2000-01-01 2000-01-02 ... 2000-01-10
```

<div id="5e034231-8d35-4366-b749-81bb24aeeb24" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('40b34892-5e50-43f7-b7f9-d40498c50e4b','5e034231-8d35-4366-b749-81bb24aeeb24')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('40b34892-5e50-43f7-b7f9-d40498c50e4b','5e034231-8d35-4366-b749-81bb24aeeb24')">Open In Tab</button></div><div id="d5c601ce-cf07-452a-93a9-ec20578d6e87" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>

#### \_\_init_\_(obj)[[source]](https://github.com/pydata/xarray/blob/main/xarray/core/accessor_dt.py#L246-L247)

### Methods

| [`__init__`](#xarray.core.accessor_dt.DatetimeAccessor.__init__)(obj)                                                           |                                                                                                                                      |
|--------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------|
| [`ceil`](xarray.core.accessor_dt.DatetimeAccessor.ceil.html.md#xarray.core.accessor_dt.DatetimeAccessor.ceil)(freq)                | Round timestamps upward to specified frequency resolution.                                                                           |
| [`floor`](xarray.core.accessor_dt.DatetimeAccessor.floor.html.md#xarray.core.accessor_dt.DatetimeAccessor.floor)(freq)              | Round timestamps downward to specified frequency resolution.                                                                         |
| [`isocalendar`](xarray.core.accessor_dt.DatetimeAccessor.isocalendar.html.md#xarray.core.accessor_dt.DatetimeAccessor.isocalendar)()      | Dataset containing ISO year, week number, and weekday.                                                                               |
| [`round`](xarray.core.accessor_dt.DatetimeAccessor.round.html.md#xarray.core.accessor_dt.DatetimeAccessor.round)(freq)              | Round timestamps to specified frequency resolution.                                                                                  |
| [`strftime`](xarray.core.accessor_dt.DatetimeAccessor.strftime.html.md#xarray.core.accessor_dt.DatetimeAccessor.strftime)(date_format) | Return an array of formatted strings specified by date_format, which supports the same string format as the python standard library. |

### Attributes

| [`calendar`](xarray.core.accessor_dt.DatetimeAccessor.calendar.html.md#xarray.core.accessor_dt.DatetimeAccessor.calendar)                 | The name of the calendar of the dates.                           |
|-----------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------|
| [`date`](xarray.core.accessor_dt.DatetimeAccessor.date.html.md#xarray.core.accessor_dt.DatetimeAccessor.date)                         | Date corresponding to datetimes                                  |
| [`day`](xarray.core.accessor_dt.DatetimeAccessor.day.html.md#xarray.core.accessor_dt.DatetimeAccessor.day)                           | The days of the datetime                                         |
| [`day_of_week`](xarray.core.accessor_dt.DatetimeAccessor.day_of_week.html.md#xarray.core.accessor_dt.DatetimeAccessor.day_of_week)           | The day of the week with Monday=0, Sunday=6                      |
| [`day_of_year`](xarray.core.accessor_dt.DatetimeAccessor.day_of_year.html.md#xarray.core.accessor_dt.DatetimeAccessor.day_of_year)           | The ordinal day of the year                                      |
| [`dayofweek`](xarray.core.accessor_dt.DatetimeAccessor.dayofweek.html.md#xarray.core.accessor_dt.DatetimeAccessor.dayofweek)               | The day of the week with Monday=0, Sunday=6                      |
| [`dayofyear`](xarray.core.accessor_dt.DatetimeAccessor.dayofyear.html.md#xarray.core.accessor_dt.DatetimeAccessor.dayofyear)               | The ordinal day of the year                                      |
| [`days_in_month`](xarray.core.accessor_dt.DatetimeAccessor.days_in_month.html.md#xarray.core.accessor_dt.DatetimeAccessor.days_in_month)       | The number of days in the month                                  |
| `days_in_year`                                                                                                              | Each datetime as the year plus the fraction of the year elapsed. |
| [`daysinmonth`](xarray.core.accessor_dt.DatetimeAccessor.daysinmonth.html.md#xarray.core.accessor_dt.DatetimeAccessor.daysinmonth)           | The number of days in the month                                  |
| `decimal_year`                                                                                                              | Convert the dates as a fractional year.                          |
| [`hour`](xarray.core.accessor_dt.DatetimeAccessor.hour.html.md#xarray.core.accessor_dt.DatetimeAccessor.hour)                         | The hours of the datetime                                        |
| [`is_leap_year`](xarray.core.accessor_dt.DatetimeAccessor.is_leap_year.html.md#xarray.core.accessor_dt.DatetimeAccessor.is_leap_year)         | Indicate if the date belongs to a leap year                      |
| [`is_month_end`](xarray.core.accessor_dt.DatetimeAccessor.is_month_end.html.md#xarray.core.accessor_dt.DatetimeAccessor.is_month_end)         | Indicate whether the date is the last day of the month           |
| [`is_month_start`](xarray.core.accessor_dt.DatetimeAccessor.is_month_start.html.md#xarray.core.accessor_dt.DatetimeAccessor.is_month_start)     | Indicate whether the date is the first day of the month          |
| [`is_quarter_end`](xarray.core.accessor_dt.DatetimeAccessor.is_quarter_end.html.md#xarray.core.accessor_dt.DatetimeAccessor.is_quarter_end)     | Indicate whether the date is the last day of a quarter           |
| [`is_quarter_start`](xarray.core.accessor_dt.DatetimeAccessor.is_quarter_start.html.md#xarray.core.accessor_dt.DatetimeAccessor.is_quarter_start) | Indicate whether the date is the first day of a quarter          |
| [`is_year_end`](xarray.core.accessor_dt.DatetimeAccessor.is_year_end.html.md#xarray.core.accessor_dt.DatetimeAccessor.is_year_end)           | Indicate whether the date is the last day of the year            |
| [`is_year_start`](xarray.core.accessor_dt.DatetimeAccessor.is_year_start.html.md#xarray.core.accessor_dt.DatetimeAccessor.is_year_start)       | Indicate whether the date is the first day of a year             |
| [`microsecond`](xarray.core.accessor_dt.DatetimeAccessor.microsecond.html.md#xarray.core.accessor_dt.DatetimeAccessor.microsecond)           | The microseconds of the datetime                                 |
| [`minute`](xarray.core.accessor_dt.DatetimeAccessor.minute.html.md#xarray.core.accessor_dt.DatetimeAccessor.minute)                     | The minutes of the datetime                                      |
| [`month`](xarray.core.accessor_dt.DatetimeAccessor.month.html.md#xarray.core.accessor_dt.DatetimeAccessor.month)                       | The month as January=1, December=12                              |
| [`nanosecond`](xarray.core.accessor_dt.DatetimeAccessor.nanosecond.html.md#xarray.core.accessor_dt.DatetimeAccessor.nanosecond)             | The nanoseconds of the datetime                                  |
| [`quarter`](xarray.core.accessor_dt.DatetimeAccessor.quarter.html.md#xarray.core.accessor_dt.DatetimeAccessor.quarter)                   | The quarter of the date                                          |
| [`season`](xarray.core.accessor_dt.DatetimeAccessor.season.html.md#xarray.core.accessor_dt.DatetimeAccessor.season)                     | Season of the year                                               |
| [`second`](xarray.core.accessor_dt.DatetimeAccessor.second.html.md#xarray.core.accessor_dt.DatetimeAccessor.second)                     | The seconds of the datetime                                      |
| [`time`](xarray.core.accessor_dt.DatetimeAccessor.time.html.md#xarray.core.accessor_dt.DatetimeAccessor.time)                         | Timestamps corresponding to datetimes                            |
| [`week`](xarray.core.accessor_dt.DatetimeAccessor.week.html.md#xarray.core.accessor_dt.DatetimeAccessor.week)                         | The week ordinal of the year                                     |
| [`weekday`](xarray.core.accessor_dt.DatetimeAccessor.weekday.html.md#xarray.core.accessor_dt.DatetimeAccessor.weekday)                   | The day of the week with Monday=0, Sunday=6                      |
| [`weekofyear`](xarray.core.accessor_dt.DatetimeAccessor.weekofyear.html.md#xarray.core.accessor_dt.DatetimeAccessor.weekofyear)             | The week ordinal of the year                                     |
| [`year`](xarray.core.accessor_dt.DatetimeAccessor.year.html.md#xarray.core.accessor_dt.DatetimeAccessor.year)                         | The year of the datetime                                         |
