function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Yannick Berthoud 7Yannick Berthoud 7 

task duedate if not week-end

Hi,

I need to create a task on the process builder the next first open day (who are not a week-end).
Sample:
My task created the monday for the thuesday, the thuesday for wednesday, but friday for monday.

Starting like "TODAY() +1 IF NOT ( ?????)"

thanks per advance :)
Best Answer chosen by Yannick Berthoud 7
Alain CabonAlain Cabon
Hi,

https://help.salesforce.com/articleView?id=formula_examples_dates.htm&type=0

Finding and Displaying the Day of the Week From a Date
CASE( MOD( date - DATE( 1900, 1, 7 ), 7 ), 
0, "Sunday", 
1, "Monday",
2, "Tuesday", 
3, "Wednesday",
4, "Thursday", 
5, "Friday", 
"Saturday" )

so a trivial formula date could be:
CASE( MOD( TODAY() - DATE( 1900, 1, 7 ), 7 ), 
1, TODAY() +1, 
2, TODAY() +1, 
3, TODAY() +1, 
4, TODAY() +1, 
5, TODAY() +3, 
null )

A+
Alain

All Answers

Alain CabonAlain Cabon
Hi,

https://help.salesforce.com/articleView?id=formula_examples_dates.htm&type=0

Finding and Displaying the Day of the Week From a Date
CASE( MOD( date - DATE( 1900, 1, 7 ), 7 ), 
0, "Sunday", 
1, "Monday",
2, "Tuesday", 
3, "Wednesday",
4, "Thursday", 
5, "Friday", 
"Saturday" )

so a trivial formula date could be:
CASE( MOD( TODAY() - DATE( 1900, 1, 7 ), 7 ), 
1, TODAY() +1, 
2, TODAY() +1, 
3, TODAY() +1, 
4, TODAY() +1, 
5, TODAY() +3, 
null )

A+
Alain
This was selected as the best answer
Yannick Berthoud 7Yannick Berthoud 7
Hi,

thanks for your answer. I currently test an example from the sample data who looks like:
CASE( 
  MOD( TODAY() - DATE( 1900, 1, 7 ), 7 ),
  5, TODAY() + 0 + 3,
  6, TODAY() + 0 + 2,
  TODAY()+ 1
)
But I really don't know why we start with DATE(1900, 1, 7), 8) and why i make "TODAY() + 0 + 3" than "TODAY() + 3"

If you can confirm me, I make TODAY()+1 for every day excepted friday +3 and saturday +2 , right ?
Alain CabonAlain Cabon
Yannick,

MOD( TODAY() - DATE( 1900, 1, 7 ), 7 )
  • DATE( 1900, 1, 7 ) = a very ancient date, 7th of January 1900 (totally arbitrary) but must be a Sunday (0) and we just want that the substraction with today remains positive.
  • Weekday Calculator – What Day is this Date? https://www.timeanddate.com/date/weekday.html
  • TODAY() - DATE( 1900, 1, 7 ) = number of days since the 7th of January 1900 and today.
  • MOD( TODAY() - DATE( 1900, 1, 7 ), 7 ) = the remaining number of days when you divide the number of days by 7 (number of day of a week)
MOD(14, 7) returns 0   => whole division ( 14 / 7 ) = 2 and 14 - 2 x 7 = 0 remaining day
( a date that is a Sunday + 7, 14, 21, ... days is always a Sunday )
MOD(15, 7) returns 1  => whole division ( 15 / 7 )  = 2 and 15 - 2 x 7 = 1 remaining day
MOD(16, 7) returns 2  remaining days

https://help.salesforce.com/articleView?id=customize_functions_i_z.htm&type=0&language=en_US

Regards