# How to use a range of DateTime as Dict keys

**URL:** <https://discourse.julialang.org/t/how-to-use-a-range-of-datetime-as-dict-keys/26688>\
**Category:** General Usage\
**Created:** [July 23, 2019, 3:34pm UTC](https://discourse.julialang.org/t/how-to-use-a-range-of-datetime-as-dict-keys/26688 "2019-07-23T15:34:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![farasa](https://avatars.discourse-cdn.com/v4/letter/f/ecae2f/32.png) [@farasa](https://discourse.julialang.org/u/farasa)\
**Post date:** [July 23, 2019, 3:34pm UTC](https://discourse.julialang.org/t/how-to-use-a-range-of-datetime-as-dict-keys/26688/1 "2019-07-23T15:34:05Z")

</div>

Hello,  
Is there any way to to do this:  
P1= DateTime(2015,08,1,12,00,00)  
P2=DateTime(2015,08,1,20,00,00)  
range(P1,P2) ==\> 3  
.  
.  
So then I would like to check time periods if they are between P1 and P2?

---

<div class="post-metadata">

**Author:** ![wookyoung](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wookyoung/32/157_2.png) [@wookyoung](https://discourse.julialang.org/u/wookyoung)\
**Post date:** [July 23, 2019, 4:04pm UTC](https://discourse.julialang.org/t/how-to-use-a-range-of-datetime-as-dict-keys/26688/2 "2019-07-23T16:04:05Z")

</div>

you could make key-value pairs by just using tuples.  
`(P1, P2) => 3`  
and could check the datetime by something like  
`P1 <= dt <= P2`

there’s a sample package using `Dates`.  
check its source code if you like.  
[https://github.com/wookay/Calendars.jl](https://github.com/wookay/Calendars.jl)

---

<div class="post-metadata">

**Author:** ![HugoTrentesaux](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hugotrentesaux/32/12583_2.png) [@HugoTrentesaux](https://discourse.julialang.org/u/HugoTrentesaux)\
**Post date:** [November 18, 2020, 9:10am UTC](https://discourse.julialang.org/t/how-to-use-a-range-of-datetime-as-dict-keys/26688/4 "2020-11-18T09:10:22Z")

</div>

Have a look to the [TimeSeries.jl](https://juliastats.org/TimeSeries.jl/latest/) package.  
It will let you specify a time range like [this](https://juliastats.org/TimeSeries.jl/latest/indexing/#Date-and-DateTime-1):

| Example | Description | Indexing value |
| --- | --- | --- |
| [Date(2000, 1, 3)] | The row containing Jan 3, 2000 timestamp | single Date |
| [[Date(2000, 1, 3), Date(2000, 2, 4)]] | The rows containing Jan 3 & Feb 4, 2000 | multiple Dates |
| [Date(2000, 1, 3):Day(1):Date(2000, 2, 4)] | The rows between Jan 3, 2000 & Feb 4, 2000 | range of Date |
