# xarray.core.accessor_dt.TimedeltaAccessor

### *class* xarray.core.accessor_dt.TimedeltaAccessor(obj)[[source]](https://github.com/pydata/xarray/blob/main/xarray/core/accessor_dt.py#L589-L658)

Access Timedelta fields for DataArrays with Timedelta-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('cffc3cd1-c926-401e-bc1d-92eb262b0510','7ffcc29e-3be0-4b4c-b441-4ff8ab6f41ca','aec1e475-f609-4fe5-b769-fbc25c22efd7','../lite/tree/../notebooks/index.html?path=bf800828_d929_45c4_8a6a_7563eb5620f6.ipynb','None')">Try it in your browser!</button></div>
```pycon
>>> dates = pd.timedelta_range(start="1 day", freq="6h", periods=20)
>>> ts = xr.DataArray(dates, dims=("time"))
>>> ts
<xarray.DataArray (time: 20)> Size: 160B
array([ 86400000000, 108000000000, 129600000000, 151200000000, 172800000000,
       194400000000, 216000000000, 237600000000, 259200000000, 280800000000,
       302400000000, 324000000000, 345600000000, 367200000000, 388800000000,
       410400000000, 432000000000, 453600000000, 475200000000, 496800000000],
      dtype='timedelta64[us]')
Coordinates:
  * time     (time) timedelta64[us] 160B 1 days 00:00:00 ... 5 days 18:00:00
>>> ts.dt
<xarray.core.accessor_dt.TimedeltaAccessor object at 0x...>
>>> ts.dt.days
<xarray.DataArray 'days' (time: 20)> Size: 160B
array([1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5])
Coordinates:
  * time     (time) timedelta64[us] 160B 1 days 00:00:00 ... 5 days 18:00:00
>>> ts.dt.microseconds
<xarray.DataArray 'microseconds' (time: 20)> Size: 160B
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
Coordinates:
  * time     (time) timedelta64[us] 160B 1 days 00:00:00 ... 5 days 18:00:00
>>> ts.dt.seconds
<xarray.DataArray 'seconds' (time: 20)> Size: 160B
array([    0, 21600, 43200, 64800,     0, 21600, 43200, 64800,     0,
       21600, 43200, 64800,     0, 21600, 43200, 64800,     0, 21600,
       43200, 64800])
Coordinates:
  * time     (time) timedelta64[us] 160B 1 days 00:00:00 ... 5 days 18:00:00
>>> ts.dt.total_seconds()
<xarray.DataArray 'total_seconds' (time: 20)> Size: 160B
array([ 86400., 108000., 129600., 151200., 172800., 194400., 216000.,
       237600., 259200., 280800., 302400., 324000., 345600., 367200.,
       388800., 410400., 432000., 453600., 475200., 496800.])
Coordinates:
  * time     (time) timedelta64[us] 160B 1 days 00:00:00 ... 5 days 18:00:00
```

<div id="aec1e475-f609-4fe5-b769-fbc25c22efd7" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('cffc3cd1-c926-401e-bc1d-92eb262b0510','aec1e475-f609-4fe5-b769-fbc25c22efd7')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('cffc3cd1-c926-401e-bc1d-92eb262b0510','aec1e475-f609-4fe5-b769-fbc25c22efd7')">Open In Tab</button></div><div id="7ffcc29e-3be0-4b4c-b441-4ff8ab6f41ca" 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#L260-L261)

### Methods

| [`__init__`](#xarray.core.accessor_dt.TimedeltaAccessor.__init__)(obj)                                               |                                                              |
|--------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------|
| [`ceil`](xarray.core.accessor_dt.TimedeltaAccessor.ceil.html.md#xarray.core.accessor_dt.TimedeltaAccessor.ceil)(freq)   | Round timestamps upward to specified frequency resolution.   |
| [`floor`](xarray.core.accessor_dt.TimedeltaAccessor.floor.html.md#xarray.core.accessor_dt.TimedeltaAccessor.floor)(freq) | Round timestamps downward to specified frequency resolution. |
| [`round`](xarray.core.accessor_dt.TimedeltaAccessor.round.html.md#xarray.core.accessor_dt.TimedeltaAccessor.round)(freq) | Round timestamps to specified frequency resolution.          |
| `total_seconds`()                                                                                            | Total duration of each element expressed in seconds.         |

### Attributes

| [`days`](xarray.core.accessor_dt.TimedeltaAccessor.days.html.md#xarray.core.accessor_dt.TimedeltaAccessor.days)                 | Number of days for each element.                                           |
|----------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------|
| [`microseconds`](xarray.core.accessor_dt.TimedeltaAccessor.microseconds.html.md#xarray.core.accessor_dt.TimedeltaAccessor.microseconds) | Number of microseconds (>= 0 and less than 1 second) for each element.     |
| [`nanoseconds`](xarray.core.accessor_dt.TimedeltaAccessor.nanoseconds.html.md#xarray.core.accessor_dt.TimedeltaAccessor.nanoseconds)   | Number of nanoseconds (>= 0 and less than 1 microsecond) for each element. |
| [`seconds`](xarray.core.accessor_dt.TimedeltaAccessor.seconds.html.md#xarray.core.accessor_dt.TimedeltaAccessor.seconds)           | Number of seconds (>= 0 and less than 1 day) for each element.             |
