# How to do to shortly create for vector of dates range selector

**URL:** <https://discourse.julialang.org/t/how-to-do-to-shortly-create-for-vector-of-dates-range-selector/50512>\
**Category:** General Usage\
**Created:** [November 20, 2020, 5:59pm UTC](https://discourse.julialang.org/t/how-to-do-to-shortly-create-for-vector-of-dates-range-selector/50512 "2020-11-20T17:59:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![programista](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/programista/32/5372_2.png) [@programista](https://discourse.julialang.org/u/programista)\
**Post date:** [November 20, 2020, 5:59pm UTC](https://discourse.julialang.org/t/how-to-do-to-shortly-create-for-vector-of-dates-range-selector/50512/1 "2020-11-20T17:59:13Z")

</div>

```julia
julia> m
6-element Array{Date,1}:
 2017-03-01
 2017-04-01
 2017-05-01
 2017-06-01
 2017-07-01
 2017-08-01

julia> (m.>Date("2017-04-01")) .& (m.<Date("2017-08-01"))
6-element BitArray{1}:
 0
 0
 1
 1
 1
 0

```

something like range(m t1,t1)  
?  
Paul

---

<div class="post-metadata">

**Author:** ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)\
**Post date:** [November 20, 2020, 6:52pm UTC](https://discourse.julialang.org/t/how-to-do-to-shortly-create-for-vector-of-dates-range-selector/50512/2 "2020-11-20T18:52:58Z")

</div>

The question title is a bit hard to understand, but is the following what you want?

```julia
julia> m = [Date("2017-$i-01") for i in 3:8]
6-element Array{Date,1}:
 2017-03-01
 2017-04-01
 2017-05-01
 2017-06-01
 2017-07-01
 2017-08-01

julia> flags = (m.>Date("2017-04-01")) .& (m.<Date("2017-08-01"))
6-element BitArray{1}:
 0
 0
 1
 1
 1
 0

julia> m[flags]
3-element Array{Date,1}:
 2017-05-01
 2017-06-01
 2017-07-01

```

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [November 20, 2020, 9:33pm UTC](https://discourse.julialang.org/t/how-to-do-to-shortly-create-for-vector-of-dates-range-selector/50512/3 "2020-11-20T21:33:47Z")

</div>

I think the question is how to create a range of dates that can be used as a selector?

```julia
julia> using Dates

julia> mydaterange = Date(2017, 3, 1):Month(1):Date(2017, 8, 1)
Date("2017-03-01"):Month(1):Date("2017-08-01")

julia> collect(mydaterange)
6-element Array{Date,1}:
 2017-03-01
 2017-04-01
 2017-05-01
 2017-06-01
 2017-07-01
 2017-08-01

```

creates a range object consisting of dates, which efficiently stores the same entries as your `m` above. Your second line suggests you want to check whether something is in a range, which could be done by something like

```julia
in(Date(2007, 5, 1):Month(1):Date(2007, 7, 1)).(m)

```

but note that using `>` and `<` isn’t necessarily the same as using `in` with a range of dates, as the range stores only the exact dates at the given steps, not all dates in between (e.g. `Date(2017, 4, 1)` is `>Date(2017, 4, 2)`, but is not `in` the date range, as the range in this example only has the first of each month)

---

<div class="post-metadata">

**Author:** ![programista](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/programista/32/5372_2.png) [@programista](https://discourse.julialang.org/u/programista)\
**Post date:** [November 21, 2020, 8:24am UTC](https://discourse.julialang.org/t/how-to-do-to-shortly-create-for-vector-of-dates-range-selector/50512/4 "2020-11-21T08:24:33Z")

</div>

> [@nilshg](#):
>
> `in(Date(2007, 5, 1):Month(1):Date(2007, 7, 1)).(m)`

It is nice

```julia
julia> m
3-element Array{Date,1}:
 2017-04-01
 2017-05-01
 2017-06-01

julia> mydaterange
Date("2017-03-01"):Month(1):Date("2017-08-01")

julia> in(m).(mydaterange)
6-element BitArray{1}:
 0
 1
 1
 1
 0
 0

```
