Date Filtering Best Practices?

Been bubbling for a while and encountered a problem filtering dates that feels like it should have a much more elegant solution than the ones I’m using. Other posts I found felt too app-specific, so I’m hoping this can be a more general resource.

The issue stems from the way dates are always stored as both a calendar date and a specific time. In a personal habit tracker I’m making, finding all instances of a habit logged TODAY requires some pretty complex filtering because “created date = current date” is trying to match the time down to the millisecond, not just the calendar date.

Solution 1 was to just format the created date and current date/time as texts. That drops the time and matches the date as you’d write it on a check or document. Seems to work and can’t think of a situation that will create problems later.

But I did encounter a weird problem with my original solution, which was to extract the date from the created date and the current date/time and try to filter to find matches. January worked great, but once February rolled around, I was including old January things in the filter. It’s because the extract date sees January 2nd and February 2nd as the same — 2=2.

In hindsight it makes sense, but I imagine this issue might drive others crazy in the future, so I wanted to share my experience. Plus, I realized that I’d encounter a similar problem next year for my habits that track weekly and monthly. Once January 2023 rolls around, my January 2022 things will show up in the filter again because, of course, 1=1 when you extract the month.

Solution 2, then, was to just add another line to the filter that extracts and matches the year as well. I can’t imagine why that wouldn’t work long term, but it still strikes me as very complex just to filter for things that happened this week or this month. Easy to say, hard to code, I guess?

Other solutions I found in the forum involved lots of inequalities and rounding the date, but these seemed even more complicated. Maybe I’m missing something that’s obvious to professional coders, though? I tried to learn how to code many times over several years, but I failed every time. Only Bubble was able to put it within reach and make it all very logical to me. This date filtering issue seemed like a weird place where coding rules still trump common sense, though. Anyway, hopefully this helps someone who’s just getting started! Other thoughts and solutions welcome and appreciated.

No, dates are just the latter — a specific point in time. Here’s a good primer/introduction to the dates in Bubble (also applicable to JavaScript as they are the same thing):

You can find a lot more info about dates by searching @keith and dates here in the forum.

Thanks, Keith! I think the beginning of your video is saying the same thing that I was trying to. To a layperson, a date is just the calendar date, like February 13th. Bubble thinks about dates differently, which makes total sense in hindsight. But as someone who’s Bubbling without any background in coding, the required mental change took a bit of time. A lot of the forum posts that I found on dates seemed to involve the same confusion, with a bit of talking back and forth before everyone got on the same page. If we’d all seen your video, it would have saved a lot of time!