Limited Time Offer: Watch All Our Bubble Tutorial Videos for Only $99 per Year!

Bubble.io Date filter: This Week

Learn how to filter data by the current week in Bubble.io for your no-code SaaS application.

In this Bubble tutorial video, I'm going to show you how you can filter by the current week on a list of dates.

Getting Started

Now, I've been putting off doing weeks because to be honest, they're a little bit more tricky and have more to be considered than filtering by last 30 days or last month or even like the current year. So let me just begin by building an expression here.

Start of the Week

So let's begin by building an expression here. So we need to get the start of this week. Now, first hurdle, what do we mean by that? Well, let's see what bubble means by that, by saying rounded down to week. So that's saying May 5. Now let me add a little bit more detail here so that it's clearer. We'll say formatted as because the big question here is, does it round down to Monday or does it round down to Sunday? So there we go. It rounds down to Sunday.

Adding More Flexibility

Now if you can work with that limitation in your bubble app, then that's going to make things a lot easier. But of course we can add a little bit more further wiggle room here of, whoops, didn't mean to delete that. Clicking in here. Taking this back, we could say rounded down to week plus one day. And let's see what that gets us.

Monday vs Sunday

So there we go. Now let's just add in the formatting so it's really clear. So now we do get Monday. Just be aware of how this could behave because what if you are on sun? Okay, so if you were midday Sunday, you would round down and that would be the start of Sunday. And then you could add one day. So then actually that's the Monday in the future, even though the expression you've built here is intended to be the Monday in the past. So if you've got a better solution, leave a comment down below. I'd love to hear it.

Alternative Approach

The way around that I found before is to effectively use a conditional. And let me just give you a little pointer on that. So let's take this expression here and add it in as a constraint. So we'd say date is equal to or less than if I just remove the formatting. Okay, so that's going to be rounded down the week plus one day, but it doesn't work if it's a Sunday. So what you could do, and I think that this is fairly inelegant, is to say current date time. So basically do a different thing if it's a Sunday. So we say current date time extract day.

Handling Sundays

Now, Sunday is a zero because it's an index value of the weekday starting on Sunday. So Sunday zero. Monday's one all the way through to Saturday being six. So we're saying if it's a Sunday, we change the data source. This is what I mean, it's inelegant. And I'd love there to be a better solution if you wanted to start your week on a Monday. So this time.

An Inelegant Solution

So if it's Sunday midday, we want to probably minus a day and then round it down and then plus a day, I think so. So we say days minus one day. So that's going to take us into Saturday, which now means that if we round down to week, we are the previous Sunday. And then if we add a day, we get to the previous Monday, like I say, it's inelegant. Let me know if there is a better solution to working with weeks. I'd love to hear it.

Latest videos

lockcrossmenu