Skip to main content
Announcements
Happy New Year! Cheers to another year of collaboration, connections and success.
cancel
Showing results for 
Search instead for 
Did you mean: 
peterstalberg
Contributor III
Contributor III

How to find number of days

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.

 

Labels (3)
2 Solutions

Accepted Solutions
MarcoWedel

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.

View solution in original post

peterstalberg
Contributor III
Contributor III
Author

Hi Marco,

Your suggestion with the AddYears function solved the problem albeit in a slight different way. Thanks!

Rgds//Peter

View solution in original post

5 Replies
Csinga
Contributor
Contributor

interval(date_final - date_debut,'dd')

MarcoWedel

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.

Peony
Creator III
Creator III

=interval_from(interval_from-interval_to)
Interval function may be used in load script as well if this make sense for you. 

peterstalberg
Contributor III
Contributor III
Author

Hi Marco,

Your suggestion with the AddYears function solved the problem albeit in a slight different way. Thanks!

Rgds//Peter

MarcoWedel

glad it helped

Marco