Filtering by Yesterday in Bubble.io
I was recently helping a Bubble app builder in a Bubble coaching session filter by dates in the application and it can be a little bit tricky. So in this Bubble tutorial video, I'm going to demonstrate how we can filter by yesterday.
Setting Up the Calendar
I've got a calendar here at the moment. It is searching for all events and it's just going to return all events. Then I've got two printouts of dates here in order to show you what's exactly going on behind the scenes.
Joining Our Community
But before I launch into that, if you are learning Bubble, if you want to launch a no-code SaaS, then there's no better place to do it than clicking the link down below and joining our community and accessing all of our videos through our website.
Targeting Yesterday's Date
In order to target yesterday, we need to sandwich a date field between "is it greater than this date" and "is it less than this date". So let's begin by getting the start of yesterday.
Getting the Start of Yesterday
I can say current date time and then I could say days minus one and then round it down to day. Let's see how that prints out. So today's date is May 8th, and there we go, we're going back to the start of yesterday.
Getting the End of Yesterday
Now how do I get the end of yesterday? Well, I could - and this is going to be using the equal to or greater than and less than operators, so this would be perfect. I can just say rounded down to day.
No Need for Subtracting a Second
Now you might think strictly I'd need to then minus one second off it, but no, you don't. This is going back to the very start of today, which is the moment after yesterday finishes, of course.
Applying Constraints
So in applying this to some constraints here, I can say date is equal to or greater than, then I need the start of yesterday which is current date time days minus one rounded down to day. Okay, so that's midnight the start of yesterday.
Setting the End Constraint
But then the end of yesterday is just less than, so it's not equal to or less than, it's just less than midnight today. So current date time rounded down to today.
Conclusion
Okay, so that's how you would create a constraint on some date fields to target events that only happen yesterday in your Bubble.io app.