Greg Hains Posted October 15, 2015 Posted October 15, 2015 Hi. I am looking for a function that allows me to determine if two date ranges overlap. Within a function I can check if a single date sits within a range of an upper and lower date (see below). It would be used to check hospital attendance for any given client over a reporting period. e.g. Client X was in a hospital bed from 30/4/2014 to 15/7/2015, and we want to see if this client was in situ during June 2015, so the function would be checking for a boolean result of two date ranges overlapping 30/4/2015...15/7/2015. Let ( [ LowerDate = DateCheck + LowerLimit ; HigherDate = DateCheck + HigherLimit ] ; If ( DateCheck ≥ LowerDate and DateCheck < HigherDate ; 1 ; 0 ) ) Does anybody know how I could modify this function please to input a range of dates rather than just a single date, perhaps using a loop or something else tricky? Any help would be appreciated. Greg
comment Posted October 15, 2015 Posted October 15, 2015 Two ranges overlap when: StartRangeA ≤ EndRangeB and StartRangeB ≤ EndRangeA Note:A Boolean expression already returns either 0 (False) or 1 (True). Your: If ( DateCheck ≥ LowerDate and DateCheck < HigherDate ; 1 ; 0 ) ) is a roundabout way of writing: DateCheck ≥ LowerDate and DateCheck < HigherDate I also didn't understand the meaning of your: LowerDate = DateCheck + LowerLimit What exactly is LowerLimit? If you want to check if a given date is within a given range, all you have to do is test for: StartRange ≤ GivenDate and GivenDate ≤ EndRange 1
Recommended Posts
This topic is 3338 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now