Constrain a list of items created today

I’ve been trying to figure how to constrain a list of items to just those created today. I can filter advanced by changing created date and today’s date and time to text and format as date. But that’s extremely slow.

Is there a way to set the created date field constraint to created today, regardless of time viewing the list?

Hi @gnelson :slight_smile: Yes, you can do this using this constraint:

Preview:

Editor:

In this example, the repeating group only displays Jobs that have been created on, or after midnight, on the current date (since the hours, minutes, and seconds are all changed to 0). That should work but let me know if not! :slight_smile:

8 Likes

nice faye, what about timezones, i have things that will expire but i want them to expire for everyone at the same time. how can that be achieved?

No problem :slight_smile: you need them to expire at the same moment for everyone (so if it’s set to expire at 9:00pm EST, then that would expire for Users at 6:00pm PST) or at the same time (9:00pm EST and then 9:00pm PST)?

yes right but i mean, have all stories expire at midnight for everyone regardless of timezone.
i found this but seems confusing, might try this later

1 Like

I’m not 100% sure, but I think you could use these constraints:

This way the Current Date/Time is already grabbing the current date for each User, and only showing that day’s Stories. For example, if it’s March 3rd for a few Users, they can access the March 3rd stories until midnight. But, if it’s March 4th for other Users, they can no longer access the March 3rd stories.

Once midnight passes for a User, those stories ‘expire’ (aren’t displayed in the RG), and the new, current day’s stories are displayed.

(Note: Since you need them to expire right at midnight, it would be best to get the updated real time using a plugin or by storing the current date/time in a custom state and refreshing every few seconds, so that the date updates at midnight automatically.)

Is that what you are looking to setup? :slight_smile:

1 Like

perf thank you

1 Like

As I’ve explained numerous times (in context, so these replies are admittedly hard-to-find), two dates (which are moments in time) happen on the same “day” (SORT OF) if a non-ambiguous text-wise comparison of the two dates (dropping time) is the same. For example:

date_1:formatted as text (format MM/DD/YYYY for example) is date_2:formatted as text (again formatted as MM/DD/YYYY)

… will be true if these dates happened on the same day… in whatever timezone the formatting happens in.

It is this last part that makes this “sort of”. In some timezones, those two moments in time may in fact happen on different calendar days and there is nothing you can do about that.

Generally speaking, the concept of " did these two things happen ‘today’ " is a question fraught with context. Did they happen “today” for WHOM? becomes the question. If the context is Current User and Current User’s timezone and both dates were created by that user in that timezone then this works as expected.

This also helps answer @anon65040322’s question, however. You can just decide on a timezone – typically, you would use UTC for this. So, if you do this comparison and pick UTC, @anon65040322, you have your answer. (But this is not generally what most Bubble programmer users would want.)

3 Likes

(@fayewatson’s first answer is correct for what most Bubble programmer users would want.)

The second one isn’t necessary. (Any date in our database CANNOT have a “created at” time greater than Current Date time +(any interval)… such a date would have been CREATED IN THE FUTURE and, so, would be a time travelling date. We need never check for creation dates greater than Current Date time… unless you actually have users who are from the future. YMMV.)

2 Likes

@keith Thanks! :slight_smile: You’re right, I think I got mixed up!

If the Current User is in California at 11pm (PST), and viewing the stories for March 3rd only – and someone in New York adds a story at 2:00am (EST) on March 4th, would that RG expression (Current Date/Time, change hours/minutes/seconds to 0, + 1 day) prevent the March 4th story from being shown until midnight for the CA User? Or that March 4th story would show because it would be considered March 3rd for the CA User?

Hey @fayewatson: As for checking for an end-of-day that has not happened yet, and is a condition that will never be found true, do not feel bad!:

Since the only arbitrary date we can create in Bubble starts with “Current Date/Time”, this concept is often used as a proxy for “arbitrary date”. So your example, where you’re TRYING to say, “Well look, if you have date1 and you wanna make sure it happens on date2, IN A CONDITION… you have to check if date1 happens AFTER the start of date2 and BEFORE the end of date2” your second example is correct… if we replace “Current Date/Time” with “date2”… but Bubble makes it hard for us to quickly make such a screenshot, yeah?)

I’ve written that exact same example for folks and then had to backpedal a bit, saying “Well, duh, we don’t have to check for the future date, but you get what I mean.” And invariably, of course, the noob user does not know what we mean.

As for your follow-on question: Doing datewise comparisons will always make things correct. So, if we have an RG displaying Posts bounded by “Current Date/Time” as the most recent Post, back to Current Date/Time+(days) -1 (which I’d do as Current Date/Time+(hours) -24)… Those are both specific moments in time (“now” back to 24 hours before “now”). They are dates – dates are specific moments in time. These are the same for everyone everywhere.

Problems only arise (and they are not problems, but gaps in our understanding of what specific moments in time ARE) when we try to REPRESENT dates (for example by rendering them as text). This is why I cringe when I see people saying stuff like “only if it happened today”… Well, that’s open to interpretation… also, that’s arbitrary. Vague + arbitrary = stupid. It’s a stupid constraint and there’s no need for ever doing that.

In this context, for example, the OP is… well, I have no idea why they’d want to do this. They are just trying to show “stuff that happened recently”. But why limit the “back in time” point? The list of posts should simply be an RG of posts, of style vertical scroll ext, sorted by Created Date descending. LET THE USER DECIDE when they stop scolling. Done.

2 Likes

Thank you so much, @keith! :slight_smile: That makes sense! I definitely have to get more familiar with working with dates/times in Bubble – will be reading your forum posts on this for sure!

1 Like

Thanks Faye that’s what I needed.

1 Like

@fayewatson - i tried using your logic to filter my search by created date within the past 24 hours. See attached. It doesn’t seem to work- any suggestions?

The goal is to filter the search results by created date within the past 24 hours

Just saved me hours… thank you!

1 Like

Hey Faye, how are you? Thanks for these info… I have a follow up question if you don’t mind… How about if I only want an action to be executed if the database has been updated over 24 hours ago? Please advise.