Hello,
Do you have any suggestion as to how I can evaluate whether a date is this week, last week, or next week, two weeks ago, and so on?
And I mean week as in from Monday to Sunday, not as in within the last 7 days to date.
Hello,
Do you have any suggestion as to how I can evaluate whether a date is this week, last week, or next week, two weeks ago, and so on?
And I mean week as in from Monday to Sunday, not as in within the last 7 days to date.
There is a free plugin that can do that I believe. I think the main use case of it was for showing when a chat message was sent.
Ignoring time zone issues completely…
All you need to do is extract the week from the dates, and then check the difference between the current week and the date’s week.
To account for the week starting on Monday, just deduct one day from each date, round down to Week, and add 1 day. Then extract the weeks of those dates.
Then use a ternary operator (format as text) to display the desired text. (personally, I’d use a RE to declare all the variables for this, to keep it nice and manageable).
That would not work across years, or would it?
Hi,
I’ve manage to do what you need with native bubble date manipulation. Please see the demo here : phenelab-29
You should have access to the editor.
The idea is to think in term of Mondays (aka starting period). We’ll calculate how many days are between a given date and last Monday.
From then we’ll determine how many weeks ago that was. Knowing that if the value is between [-7;0] that was last week, if it’s between [-14;-7] that was 2 weeks ago, etc… it also works with future dates, if it is between [0;7] it is this week, [7;14] it is next week etc…
Then a division and some flooring and you get to know how many weeks that was (or will be)
@umiumansa pls do not follow @bonjour_17’s suggestion. That is a terrible way to approach it. @adamhholmes offered the priper solution
OP needs that to work accross years as well. Would you mind elaborating how to make this work by extracting the month from 2 dates?
It would if you incorporate a check of the year value as well by extracting the year component of the dates.
This will bring the need for extra logic as there are some years with 52 and some years with 53 weeks.
No it won’t, it will bring the logic of just needing to verify if the weeks are in the same year or not.
The concern from the OP as expressed below
Is likely due to the fact that following the approach outlined by Adam there could be a situation in which the app will compare the dates of March 1st 2024 and March 8th 2023 and see that March 1st 2024 is last week when compared to March 8th 2023 if the YEAR component is not taken into account, and so to solve for that, the year component needs to be extracted and used to determine if March 1st 2024 compared to March 8th 2023 is last week or not, which it obviously is not when the Year component is considered, but if the year is not considered, then March 1st versus March 8th certainly looks like Last Week.
The OP I do not believe is concerned with counting how many weeks are in a year.
OP probably need that system to be reliable even at the beginning and the end of the year.
The method of extracting the week number from the date was mentionned earlier, and backed-up by someone else.
I suppose the method consists in comparing the week numbers (current_week - date_week = difference)
→ that method brings difficulties around the beginning and the end of the year.
If every year had the exact same amount of weeks that could easily work with basic comparisson based on the fact that there are 52 weeks per year. But that will bring errors when years have 53.
Example : 2020 had 53 weeks. 2021 had 52 weeks.
Correct… so you’ll need to account for that…
A more reliable (and simpler) way, if needing to account for dates that cross years, is just to count the difference in days between the two dates, and divide by 7 (instead of using the difference in week numbers).
That will always give an accurate results, regardless of whether you’re crossing years.
e.g.
Current date rounded down to Monday - other date rounded down to Monday: formatted as days / 7
I understand now, the outline approach was using week, but week is a number, as in which week of the year is it (ie: 1st week, 34th week, or 52nd week).
@umiumansa What is your use case for this and how are you implementing it into a feature and what is the need for the ability to determine
and how far is the so on suppose to go? Is it suppose to say this was 4 weeks ago, 100 weeks ago etc. in the comparison and related display to the user?
This topic was automatically closed after 70 days. New replies are no longer allowed.