Date(year + quarter)?

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.

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:

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
1 Like
yrqtr(d) = string(year(d),"Y",quarterofyear(d),"Q")

although I would typically use

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.

I’ve just created this package:

It works as follows:

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