0
I’m developing a system in Laravel with Fullcalendar v4. When creating an "event", this event has execution date (dtstart) and expiration date (until), however there will be intermediate events, based on the amount of events reported. The question is: how to calculate the intermediate dates between 'dtstart' and 'until', that is, the difficulty is not to encode but to find the correct formula.
Example:
$dtstart = '2019-04-01';
$until = '2019-05-30';
$eventos = 5;
In this example, I have a difference of 59 days (until - dtstart -1). I need to generate more '3' events/dates, and these events are between 'dtstart' and 'until', so distributed between this given range. Of course these values can be other.
Thank you!
Divide the number of days you have by the number of events minus 1. If you have 59 days for 5 events, the interval will be 59/4. Isn’t that right? Then the rule to round up is up to you.
– Woss
Thanks for the suggestion, frankly, I’m not sure for the simplicity of your answer and even for my scenario... I was working out so many calculations, one more complex than another, that I was already losing it and I thought... it’s not possible not to have a basic calculation for it. But I’ll try again with your model.
– Magno Alberto
By sampling, demonstrates to meet the following formula:
$diff_days = $dtstart->diff($until, true)->days; round($diff_days / $events);
. Again thanks for the suggestion.– Magno Alberto
It doesn’t need to be by sampling, mathematically it is proven that it will suit you in all situations.
– Woss
Thanks again for the help, without your suggestion, maybe I’d be stuck in complex calculations. Anyway, follow to share what the final solution to my scenario.
$diff_days = $until->diff($dtstart, true)->days; round(($diff_days - 1) / ($disparo_quant + 1) )
; A small adjustment in the calculation made all the difference.`– Magno Alberto