I’m trying to obtain the Duration (or start and end dates) of an arbitrary ‘quarter’ in Luxon.
For example, suppose I want the beginning and ending dates of the 3rd quarter knowing only the quarter:
JavaScript
x
4
1
const quarterInQuestion = 3;
2
3
const startDateOfQuarter = DateTime.fromFormat(quarterInQuestion.toString(), 'q');
4
This will give me the start date of the quarter, but how can I obtain the end date as well. I’ve looked into Durations and Intervals but can’t seem to get anything to work yet.
Many thanks!
Advertisement
Answer
I think you want the endOf
method, to which you can pass the period that you want the end of from a date.
JavaScript
1
3
1
const startDateOfQuarter = DateTime.fromFormat('3', 'q');
2
const endDateOfQuarter = startDateOfQuarter.endOf('quarter')
3