If a date is within a date range

If I want to check if a date is within a date range, how do I do that? The following expression only returns yes if the two date ranges are equal:

31

tid(time) is a range.

“contains point”

In date range-land, “contains” means:

Does THIS range of time [defined by one point and another point-in-time] fully enclose THAT range of time [defined by another point and YET ANOTHER point-in-time]?

But since a time range (date range) contains an infinite number of individual points-in-time, it also makes sense to ask:

Does THIS range of time [defined by one point and another point-in-time] contain a single point-in-time?

And, so, we have two syntaxes for this: “contains” and “contains point”. “Contains” is the range-wise comparison. “Contains point” is the range-to-point-wise comparison.

Ranges (both time and number ranges) have this unique property. No other primary data type does.

Consider the following:

  • Does it make sense to ask: “Does string ‘Keith’ contain the integer 2?” No, that’s nonsensical. A string cannot contain an integer and vice versa.

  • But it DOES make sense for a compound data type like a date range to contain an individual date. Similarly, it DOES make sense for a data type like a numeric range to contain an individual numeral.

  • But, no, this is not well documented.

  • Ranges are a bit like complex custom data types in this way. Does it make sense for User to contain “Keith”? Well, sort of. It makes sense to ask - does a list of Users’s First Names contain “Keith”? (This is, “give me the list of all Users whose first name is Keith”.) Similarly, we can ask of one single User – does this User’s First Name equal “Keith”? (This is a boolean expression. It is true if User’s First Name is “Keith” and false otherwise.)

When we ask a date range if it contains a date, we do it this way:

date_range _contains_ point date

… or we can construct the date_range on the fly:

dateX <- range -> dateY contains date

(Note that date operators can only be used after dateX, so if you need to do date operations on one endpoint of your range, you do it in the leftmost date position. Example:

Current Date/Time+(hours)2 ← range → Current Date/Time

is a date range that starts at now and ends 2 hours from now. The order of endpoints in the range does not matter. The less becomes :start and the greater becomes :end.)

We unfortunately cannot write: date is contained by date_range… “contained by” is a range operation, so we only see it after a date range.

[The above part was edited for accuracy.]

9 Likes

Thanks keith for your informative answer. The thing is, “contains point” doesn’t come up as an option:

08

Or:

49

Again, only date ranges will have “contains point”:

DateX <- range -> DateY contains point DateZ

is true if DateZ is within the time range described by DateX and DateY.

On the second point: I was writing from memory and made a boo-boo here! You CANNOT do:

date is contained by date_range

Apologies. You can only do:

daterangeX is contained by daterangeY

The field “tid” is a date range and the AirDate/TimePicker's value is a date, right?

Alright, got it. Thanks!

This topic was automatically closed after 70 days. New replies are no longer allowed.