# Date(year + quarter)?

**URL:** <https://discourse.julialang.org/t/date-year-quarter/37782>\
**Category:** General Usage\
**Tags:** dates\
**Created:** [April 17, 2020, 8:04pm UTC](https://discourse.julialang.org/t/date-year-quarter/37782 "2020-04-17T20:04:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![BMval](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bmval/32/7647_2.png) [@BMval](https://discourse.julialang.org/u/BMval)\
**Post date:** [April 17, 2020, 8:04pm UTC](https://discourse.julialang.org/t/date-year-quarter/37782/1 "2020-04-17T20:04:53Z")

</div>

Good day.

I have a quarterly dataset. Would you suggest, How I can keep dates in format: year + quarter. For instance: 2010Y3Q.

So Dates allow creating date by date(year, month). Is it some way to create date by date(year, quarter)?

Thank you in advance.

---

<div class="post-metadata">

**Author:** ![pixel27](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pixel27/32/8902_2.png) [@pixel27](https://discourse.julialang.org/u/pixel27)\
**Post date:** [April 17, 2020, 8:23pm UTC](https://discourse.julialang.org/t/date-year-quarter/37782/2 "2020-04-17T20:23:45Z")

</div>

[https://docs.julialang.org/en/v1/stdlib/Dates/#Dates.DateFormat](https://docs.julialang.org/en/v1/stdlib/Dates/#Dates.DateFormat)  
Doesn’t appear to understand quarter…so I think you are going to have to do it the ugly way, create your own formatter function that looks at the month and year and generates the correct text. Maybe something like:

```julia
function quarter(d)
   q = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4]
   "$(year(d))Q$(q[month(d)])"
end
```

---

<div class="post-metadata">

**Author:** ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Post date:** [April 17, 2020, 10:10pm UTC](https://discourse.julialang.org/t/date-year-quarter/37782/3 "2020-04-17T22:10:27Z")

</div>

```julia
yrqtr(d) = string(year(d),"Y",quarterofyear(d),"Q")

```

although I would typically use

```julia
yrqtr(d) = string(year(d),"Q",quarterofyear(d))

```

Both of these just create strings but does still allow for things like `sort` to continue to work correctly.

---

<div class="post-metadata">

**Author:** ![matthieu](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@matthieu](https://discourse.julialang.org/u/matthieu)\
**Post date:** [April 18, 2020, 12:00am UTC](https://discourse.julialang.org/t/date-year-quarter/37782/4 "2020-04-18T00:00:35Z")

</div>

I’ve just created this package:

> **[GitHub - matthieugomez/PeriodicalDates.jl](https://github.com/matthieugomez/PeriodicalDates.jl)**
>
> Contribute to matthieugomez/PeriodicalDates.jl development by creating an account on GitHub.

It works as follows:

```julia
 julia> using Dates, MonthlyDates
 julia> dtq = QuarterlyDate(1990, 1)
 # 1990q1
 julia> dtq + Quarter(1)
 # 1990q2

```
