Projecting quarterly dates using datetime variables
Mostrar comentarios más antiguos
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
3 comentarios
Looks like a bug although I expect TMW will claim it is WAD as the definition is
Q = fix(calmonths(t)/3)
The colon expansion doesn't look at the dynamic nature of the interval as your tests show during the building process...
Hmmm....what is a convenient workaround????
Well, nothing really jumps out at me other than some sorta' nasty gyrations with eomday to try to pass a vector of day increments based on the start/end dates wanted.
This is a bug report/enhancement request...I've noted elsewhere that datetime is a work in progress with much yet to be done to make it truly functional; this appears yet another wart.
Peter P has seen and commented on a number of the time-related threads and sometimes has clever ways to use the functions that aren't apparent to the neophyte or shows how they were intended to be used for real examples--so many of the examples in the doc are just too trivial to be of any value for real situation.
"Looks like a bug..."
I disagree: it looks like a badly posed definition. Consider the first of the month:
datetime(2013,05,1):calquarters(1):datetime(2014,05,1)
What would the expected output be? What about the second of the month?:
datetime(2013,05,2):calquarters(1):datetime(2014,05,2)
And so on up until 30. This is ambiguous because what humans see as "intuitive" is really an unrelated operation. I agree with Peter Perkins' comment below: dateshift is the correct way to achieve this task.
dpb
el 15 de Ag. de 2017
I agree I think it a definition issue; see follow-up...I pose an alternate syntax altho I think the "intuitive" solution is the more likely one users would expect in a high fraction of instances so should rate higher on the scale of how to implement/make the definition. The point of Matlab is the RAD arena; things that take extra effort to fix up detract from that objective....and, of course, that's all in the realm of $0.02, imo, ymmv, etc., etc., etc., ... caveats. :)
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Dates and Time en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!