# 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#L606-L675)

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('612eb489-ff68-47ba-9405-af02340887f4','3a2d1c27-9164-4f9b-a5c7-e609b2568fae','9583e513-1bdb-4c09-8402-1c6224ef36fd','../lite/tree/../notebooks/index.html?path=9cab85da_7ede_41f8_9b2e_37242ad3daca.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="9583e513-1bdb-4c09-8402-1c6224ef36fd" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('612eb489-ff68-47ba-9405-af02340887f4','9583e513-1bdb-4c09-8402-1c6224ef36fd')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('612eb489-ff68-47ba-9405-af02340887f4','9583e513-1bdb-4c09-8402-1c6224ef36fd')">Open In Tab</button></div><div id="3a2d1c27-9164-4f9b-a5c7-e609b2568fae" 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.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             |
