MATLAB: Projecting quarterly dates using datetime variables

calmonths functioncalquarters functiondatetimequarterly dates

Hi there,
I'm trying to project quarter-end dates but the calquarter (or calmonth) function doesn't seem to work correctly if the start date is a month with 30 days.
Here's an example where it works correctly (start date is month with 31 days). The result in this case is adjusted for months with 30 and 31 days:
>> t = datetime(2013,05,31):calquarters(1):datetime(2014,05,31)
t =
31-May-2013 31-Aug-2013 30-Nov-2013 28-Feb-2014 31-May-2014
Here is an example where it doesn't work correctly (start date is month with 30 days). The result in this case has the 30th of each month as quarter-end, which is not correct:
>> t = datetime(2013,06,30):calquarters(1):datetime(2014,05,31)
t =
30-Jun-2013 30-Sep-2013 30-Dec-2013 30-Mar-2014
I appreciate any help with this. Many thanks!!!
Alex

Best Answer

OH! Wait! That comment re: Peter reminds me of a trick he did show earlier that may fixup the problem-- dateshift. Let's see with your bum example:
>> tq = datetime(2013,06,30):calquarters(1):datetime(2014,05,31)
tq =
30-Jun-2013 30-Sep-2013 30-Dec-2013 30-Mar-2014
>> dateshift(tq,'end','month')
ans =
30-Jun-2013 30-Sep-2013 31-Dec-2013 31-Mar-2014
>>
VOILA! I agree it should work "out of the box", but there at least there is a reasonable way to clean up the mess...
You could even wrap the original call in the dateshift function and do it in a single step.