I am currently making a logging app where users will have the opportunity to log shift hours. The hours would be required on a weekly basis, with each week starting at midnight on sunday. That said, if I want to get the amount of shifts they have completed since the start of this week, I need a way to be able to get the date of the “Last sunday” and compare the dates the logs for that user were created accordingly. I haven’t been able to find any expressions or plugins that work for this.
TLDR: I’m looking for ways to get the date of the last Sunday before any given date.
This plugin should do the trick:
Hope this helps
I was actually using this plugin originally. I’m not sure if I was using it incorrectly, but it didn’t work for me. Whenever I tried to get “this Sunday” it would just return the current date
Hi there, @mcarey02005… if I understand your post correctly, the following example is one way to achieve your desired result.
If you extract the day from a given date and then subtract that number of days from the given date, you will always end up on the previous Sunday from the given date.
To see this concept in action, add a date picker to a page… for this example, the date picker is called given date. Then, add an input to the page and set the Initial content as follows…
Finally, add another date picker to the page and set its Initial content as follows…
With those inputs in place, the second date picker will always show the date of the Sunday that is just prior to the date selected in the first date picker.
Anyway, that’s one way to do what you are trying to do, and I hope this helps.
Sorry if my initial question was haphazardly worded. I will try to be more specific here. I have a list of entries stored under a data type. I want to sort this list so that I will have only entries that were AFTER the last sunday. I will show you what I currently have with this plugin, and why it doesn’t work.
The red circle is what will attempt to sort the entries of shift logs and then get the minutes of said logs and compare them to a minimum number.
The blue circle is the logic I’m using to try to get the date of the last Sunday. The first part that says “Next Sunday” is the plugin that was mentioned in an above response that does not seem to be working for me. Ideally, it would get the next Sunday and I would just subtract 7 days to get the last Sunday. However the problem was that the “Next Sunday” expression returned the current date.
Also, if this is still the solution, “If you extract the day from a given date and then subtract that number of days from the given date, you will always end up on the previous Sunday from the given date”, would you mind elaborating or providing an example. I’m getting lost in the wording. Thanks!
Hi, @mcarey02005… I rarely use plugins, and I don’t know how that day of week plugin works. So, the solution I would use is the one I described, and I will try to explain it a bit better.
When you extract the day from a date, you get a number from 0 to 6 that corresponds to the date’s day of the week, where Sunday = 0, Monday = 1, Tuesday = 2, and so on. So, if you extract the day from a date that is, say, a Wednesday, the day will be 3. If you then subtract 3 days from that Wednesday, you will have the date of the previous Sunday. If this concept still isn’t clear, recreate the example I gave in my initial response, and you will see how every date you select in the first date picker produces the date of the previous Sunday in the second date picker.
Once you understand the concept I have described above, you should be able to use it to build a constraint that returns all of the things in your data type where the
Clock In date is greater than or equal to the date associated with the most recent Sunday. Here is an example where the current date is used in the constraint…
Because I can’t find a way when building the constraint to extract the day from the current date and multiply it by -1 in the constraint itself, I added a hidden input to the page to get the number of days that need to be subtracted from the current date…
Then, the constraint itself would look something like this…
You would obviously have to play around with this idea to get it to work for your exact purpose, but hopefully I was able to make the concept clearer so it can help you get down a path.
Thank you very much mike, this is exactly what I’m m looking for. I must have missed it in the documentation somewhere. Have a great week! -Matt
This topic was automatically closed after 70 days. New replies are no longer allowed.