html_url,issue_url,id,node_id,user,created_at,updated_at,author_association,body,reactions,performed_via_github_app,issue
https://github.com/pydata/xarray/issues/6412#issuecomment-1081869682,https://api.github.com/repos/pydata/xarray/issues/6412,1081869682,IC_kwDOAMm_X85AfAVy,6628425,2022-03-29T13:25:46Z,2022-03-29T13:25:46Z,MEMBER,"I agree this should be better documented.
> Here when I want to retrieve the year of datetime, instead of casting back to an array of object & using datetime.year, it's handy to use built-in numpy datetime64 conversion.
The recommended way to extract datetime components, like the year, is to use the [`DatetimeAccessor`](https://docs.xarray.dev/en/stable/generated/xarray.core.accessor_dt.DatetimeAccessor.html). For example if you have a DataArray of datetime-like values (whether they are of type `np.datetime64[ns]` or `cftime.datetime`) you can do something like this:
```
da.dt.year
```
and it will return a DataArray containing the year of each datetime (for more information see the [""Datetime components""](https://docs.xarray.dev/en/stable/user-guide/time-series.html#datetime-components) section of the documentation).","{""total_count"": 1, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 1, ""rocket"": 0, ""eyes"": 0}",,1180565228
https://github.com/pydata/xarray/issues/6412#issuecomment-1078904879,https://api.github.com/repos/pydata/xarray/issues/6412,1078904879,IC_kwDOAMm_X85ATsgv,6628425,2022-03-25T10:59:49Z,2022-03-25T10:59:49Z,MEMBER,"This is a common point of confusion, but is in fact expected. Xarray intentionally converts any `np.datetime64` type to `np.datetime64[ns]`. The primary motivation is compatibility with pandas, which xarray relies on for time indexing and other time-related operations through things like `pandas.DatetimeIndex` or the `pandas.Series.dt` accessor (see, e.g., discussion in https://github.com/pydata/xarray/issues/789).
May I ask what your reason is for requiring a lower-precision datetime type? In xarray we have tried to provide alternatives (e.g. [through `cftime`](https://docs.xarray.dev/en/stable/user-guide/weather-climate.html#non-standard-calendars-and-dates-outside-the-timestamp-valid-range)) for use-cases like longer date ranges.","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,1180565228