You need to sign in to do that
Don't have an account?
Ross McLeod 3
Two dates within same week
Hi
I have a requirement to create a validation rule which validates a start and end date are within the same week.
* Week is classed as Monday to Sunday
* Both dates must fall within the same week
I'm not sure how to accomplish this as I believe that Salesforce week os Sunday to Saturday.
Thanks
I have a requirement to create a validation rule which validates a start and end date are within the same week.
* Week is classed as Monday to Sunday
* Both dates must fall within the same week
I'm not sure how to accomplish this as I believe that Salesforce week os Sunday to Saturday.
Thanks
>> https://developer.salesforce.com/forums/?id=906F0000000MNWhIAO
I think the above link has a similar implementation that you can try checking once.
I am adding the mentioned best answer for quick reference:
Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks.
Hi Ross,
Please find the solution.
Go to objectManager ==>choose your object ==> choose Validation rule
Put your error message : Same week
Please do the needful changes.
Please mark it as the best Answer
Thank You
Please follow below code in validation rule:
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
If we use: we just find out that the dates are less than 7 days apart , which could be a Thursday Start Date to the Next Tuesday End date.
But if we try: so the two days are 7 Days apart and in the Same week, assuming Sunday to Saturday.
Now to handle the Monday start versus Sunday Start. for explanation of WEEKDAY will return a value between 1 and 7 matching the day of the week. 1 being Sunday thru to 7 being Saturday.
but we need to work Monday as 1 thru to Sunday as 7
so we add 6 to the weekday result, divide by 7 and get the Modulo (MOD - Returns a remainder after a number is divided by a specified divisor.)
this resets the number to being Sunday as a 7, hence a higher number than Monday as a 1.
hope that throws some light on things.
regards
Andrew
Start Date: 10/05/2021 (Monday) - End Date 11/05/2021 (Tuesday) Result: Validation rule shows
Start Date: 10/05/2021 (Monday) - End Date 14/05/2021 (Friday) Result: Validation rule shows
Start Date: 10/05/2021 (Monday) - End Date 15/05/2021 (Saturday) Result: Validation rule shows
Start Date: 10/05/2021 (Monday) - End Date 17/05/2021 (Sunday) Result: No rule shows
Start Date: 10/05/2021 (Monday) - End Date 18/05/2021 (Monday) Result: No rule shows
Any ideas?
Try adjust the +6 to +5
cheers
Andrew
So if the start date is Monday 10/05/2021 then the end date must be Less than or equeal to Sunday 16/05/2021.
Thanks for your patients.
I have created a formula field with the following code: And here is a shot of the page that is displayed - it includes the "adjust" fields which i used to test the calculation of the numbers
I'm unsure why you aren't getting similar results.
regards
Andrew