@dan1 points this out a little bit, but to drill down a bit:
The Date datatype in Bubble is like (probably IS) the Date datatype as found in JavaScript. While we call them “dates”, these things are date/time objects.
As a human being, as I go about my day, I think about “today’s date” as being the date shown to me on my calendar (actually, the date my phone shows to me).
But that’s not the same thing as a date/time object. A date/time object is bigger and tells us a lot more stuff. A date/time object describes a unique moment in time to a certain level of precision.
So, consider that you and I have a conference call set up for tomorrow at Noon, my time. Unless you are also on the US West Coast and in Pacific Daylight Time, the time on YOUR calendar for that call will be different (heck, depending on where you are, that might even be at the start or end of a different calendar date!).
However, both of those calendar entries would refer to exactly the same moment in time. (Unless we are in roughly the same place, the time-of-day and even date-indicated-on-the-calendar are likely different.)
A date in Bubble (and in JavaScript and in computer-land in general) is like this. Think of it as a unique moment-in-time. Obviously, unique moments-in-time would be displayed differently to people in different places. Where I sit right now, it’s not yet Happy Hour. If you are in New York, it may be Happy Hour for you. However, we’re both at the same absolute time (which we call “now”).
So, anyway, what you’re doing is wanting to compare ONLY what we think of as “the date parts” of two moments in time (date/time objects).
There are several ways to do this. Basically, they all involve either ignoring or manipulating the time part:
- First, let’s clarify what it means that two date/time objects share the same date part. Since the two objects could have completely different TIME parts, but we don’t care if the time part on one is earlier or later than the other, we can’t simply use < or > comparisons. Consider this:
a. thing1_date and date_x both have the same date part (let’s say it’s today 08/10/2018).
b. but thing1_date will only be “<” date_x if the TIME PART of thing1_date is earlier than the time part of date_x
This will be important when we look at option #1, below. For all of them, we’re going to assume that thing1_date and date_x have the same date part (which we’ll describe as today’s date August 10, 2018 which I write as 08/10/2018).
- We can do it using date/time comparisons. If we choose to do it this way, what we need to do is make sure that date_x’s time part is late enough that ANY date/time object that happens on date_x’s date part will happen at a time EARLIER than date_x’s time part.
In Bubble terms the very last moment of date_x’s day that we can access is:
08/10/2018 at 23:59:59
We can manipulate date_x so that its time is 23:59:59 but for whatever reason, we can’t get at its milliseconds in Bubble. (JavaScript dates have a milliseconds part that goes to .999).
So there’s an outside chance that thing1_date is like 08/10/2018 at 23:59:59:999 and, while it has the same date part, it might actually be later than the latest time we can assign to date_x (and so, it would evaluate as NOT being earlier than date_x).
So, to perform this comparison in date/time space what we would do is actually use the NEXT day at a time of 00:00:00.
So the comparison would be like:
if thing1_date < date_x:+days 1:set [hours, minutes, and seconds] 0
Obviously, this is kind of a giant pain in the butt unless you’ve already imagined the problem in this way. But the point is, you CAN do this comparison in date/time space, it just takes some thinking and preparation.
I actually think that this is what you want to do. It’s not very hard, but you have to understand the “whys” of date math. (And hopefully I’ve explained it well enough.)
Also, all of the above MAY explain why the date/time comparisons are just < and >, but not “is” (equivalency, what we might think of as “=”). It is of little value to understand if two date/time objects are, in fact, identical down to the millisecond.
However, let’s say that I am the one constructing the dates in code. And I construct all my dates such that the time part is always the same thing (like 00:00:00:000). It is a bit annoying that I can’t just check that one thing I constructed isn’t equal to some other thing I constructed using “is”. #shrug
- We can do it by comparing month, day and year component of our two date/time objects. In this case, it’s a little easier to think about and this is what @dan1 suggested.
Basically, thing1_date and date_x share the same date part if:
thing1_date:extract day is date_x:extract day AND
thing1_date:extract month is date_x:extract month AND
thing1_date:extract year is date_x:extract year
But you’re not looking for an exact match… You want to know when thing1_date part is less than or equal to the date part of date_x.
It’s actually REALLY HARD to do that using this technique of extraction. The comparison would have to work like this:
if thing1_date:extract year < date_x:extract year then thing1_date is definitely earlier
if thing1_date:extract year > date_x:extract year then thing1_date is definitely NOT earlier
ELSE if thing1_date:extract year = date_x:extract year AND thing_1:extract month < date_x:extract month then thing1_date is definitely earlier…
I could go on, but you can see that the next comparison is would be to compare the day part if the years and months are the same.
That’s a lot of bull-hockey and option 1 looks pretty good right now, eh?
- This option doesn’t help you, but a lot of folks, when they see questions like this think that the poster is asking about date equivalency. A real easy way to do that (just find if the date parts are the same) is to convert the dates to text (string) representations:
if thing1_date:formatted as 08/10/2018 is date_x:formatted as 08/10/2018 then these are the same date.
But again, this doesn’t help us with the “earlier” part.
- Back to the date comparison way described in #1: What if you don’t just want to know if thing1_date is earlier than date_x, but it must also to greater than some other time/date. That is, what if it’s in a range where the end of the range is represented by date_x and the start of the range is date_start?
(Again, remember we are now talking about date/time objects here once again.)
In Bubble this is:
date_start<- range ->date_x contains point thing_1_date
Again, the end date (date_x) should be time 00:00:00 on the day AFTER you want the range to end for the reasons I discussed above.
Tl;dr: Welcome to date math!
Hope this helps.