Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
I have a number of periods and intervals in a generic day-month format. My challenge is how to calculate the number of days an interval intersects with a period as per the example table below.
I have tried with the DayNumberOfYear() function, which works fine as long as I'm in the same year, i.e. line 1, but when intervals and periods span over 31-dec, as per line 2 & 3, this approach is no longer giving correct results.
period_start | period_end | interval_from | interval_to | #intervall_days_in_period |
12-dec | 20-dec | 01-dec | 15-dec | 3 |
05-dec | 20-jan | 20-dec | 10-jan | 21 |
25-dec | 15-feb | 20-jan | 01-mar | 27 |
Any assistance on how to solve this is highly appreciated. Regards//Peter
PS. interval_from & interval_to are user input hence solution need to be outside of the script.
without year information this calculation is a bit ambiguous, but maybe something like
RangeMax(RangeMin(AddYears(period_end,-(period_end<period_start)),AddYears(interval_to,-(interval_to<interval_from)))-RangeMax(period_start,interval_from),0)
might help you here.
Hi Marco,
Your suggestion with the AddYears function solved the problem albeit in a slight different way. Thanks!
Rgds//Peter
interval(date_final - date_debut,'dd')
without year information this calculation is a bit ambiguous, but maybe something like
RangeMax(RangeMin(AddYears(period_end,-(period_end<period_start)),AddYears(interval_to,-(interval_to<interval_from)))-RangeMax(period_start,interval_from),0)
might help you here.
=interval_from(interval_from-interval_to)
Interval function may be used in load script as well if this make sense for you.
Hi Marco,
Your suggestion with the AddYears function solved the problem albeit in a slight different way. Thanks!
Rgds//Peter
glad it helped
Marco