# How to filter Date data column in a DataFrame

**URL:** <https://discourse.julialang.org/t/how-to-filter-date-data-column-in-a-dataframe/110485>\
**Category:** General Usage\
**Tags:** dates, dataframes\
**Created:** [February 20, 2024, 11:03pm UTC](https://discourse.julialang.org/t/how-to-filter-date-data-column-in-a-dataframe/110485 "2024-02-20T23:03:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![PeX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pex/32/49986_2.png) [@PeX](https://discourse.julialang.org/u/PeX)\
**Post date:** [February 20, 2024, 11:03pm UTC](https://discourse.julialang.org/t/how-to-filter-date-data-column-in-a-dataframe/110485/1 "2024-02-20T23:03:59Z")

</div>

Hi everyone,

I have a DataFrame with Dates type in one column named “Date” (the rest of the columns are with regular data). I want to filter the dataframe to have data only between years 2015 and 2019.  
I tried:

```julia
df[@. 2015 <= Dates.year(df.Date) <= 2019, :]

```

However, I get the following error:

```julia
MethodError: no method matching getindex(::DataFrames.DataFrame, ::Tuple{BitVector, Colon})

```

The data type `dump(df.Date)` is:

```julia
Array{Dates.Date}((120,))
  1: Dates.Date
    instant: Dates.UTInstant{Dates.Day}
      periods: Dates.Day
        value: Int64 735264
...

```

Any ideas on how to do that efficiently?

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [February 20, 2024, 11:46pm UTC](https://discourse.julialang.org/t/how-to-filter-date-data-column-in-a-dataframe/110485/2 "2024-02-20T23:46:04Z")

</div>

> [@PeX](#):
>
> `@. 2015 <= Dates.year(df.Date) <= 2019`

Have you tried writing all the dots instead of using the macro?

```julia
df[2015 .<= Dates.year.(df.Date) .<= 2019, :]
```

---

<div class="post-metadata">

**Author:** ![contradict](https://avatars.discourse-cdn.com/v4/letter/c/ac91a4/32.png) [@contradict](https://discourse.julialang.org/u/contradict)\
**Post date:** [February 20, 2024, 11:53pm UTC](https://discourse.julialang.org/t/how-to-filter-date-data-column-in-a-dataframe/110485/3 "2024-02-20T23:53:25Z")

</div>

Manually adding dots works as does

```
df[(@. 2015 <= Dates.year(df.Date) <= 2019), :]

```

Otherwise the `@.` grabs the whole tuple and that gets passed as one argument rather than as two separate arguments.

---

<div class="post-metadata">

**Author:** ![PeX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pex/32/49986_2.png) [@PeX](https://discourse.julialang.org/u/PeX)\
**Post date:** [February 20, 2024, 11:58pm UTC](https://discourse.julialang.org/t/how-to-filter-date-data-column-in-a-dataframe/110485/4 "2024-02-20T23:58:30Z")

</div>

You guys helped a-lot! I couldn’t figure out what’s wrong
