3

I have a scenario wherein, there is a field "A" which takes "Date" value. Field "B" should display the Weekend date based on field value "A". Like if "A" = 21-Thursday. Field "B" should display date "23rd" as it is the weekend of specified date. Any suggestions pls?

3

This should work for you:

CASE( 
MOD(field A- DATE(1900, 1, 6),7), 
0, field A + 7, 
1, field A + 6, 
2, field A + 5, 
3, field A + 4, 
4, field A + 3, 
5, field A + 2, 
6, field A + 1, 
NULL 
)

Note that if a record is created on a Saturday, this will calculate the following Saturday. If you'd like to change that and return the same date you can just remove the '+7' from the first statement.

Hope this helps.

|improve this answer|||||
  • Thanks for that. A little more help pls. What if there is a field "A" which takes "Date" value. Field "B" should display the Weekend date based on field value "A". Like if "A" = 21-Monday-2015. Field "B" should display date 27-Sunday-2015 as it is the weekend of specified date. – Praveen Dec 21 '15 at 6:43
  • you mean u need days in characters? like you mentioned "Monday" or "Sunday"?. – mohammed azarudeen Dec 21 '15 at 6:54
0

Apex Date methods have a function called ToStartOfWeek which returns start of the week depending on the users locale. Once you have that, it should be easy to get the weekend date.

Date weekStart = myDate.toStartofWeek();

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.