You need to sign in to do that
Don't have an account?
Trigger to calculate End Date after adding No_Of_Days to Start Date
Hi,
I have written below trigger to calculate due date based on addition of no of days to start date(excluding Saturday and Sunday)
trigger calculateDueDate on Job__c (before insert,before update) {
for (Job__c j : Trigger.New)
{ if(j.Start_Date__c != null && j.No_of_Days__c != null) { DateTime st = j.Start_Date__c; double d=j.No_of_Days__c; Integer i=d.intValue(); DateTime et = st.addDays(i); while(st<et) { Integer count=0; if(st.format('E')=='Sat' || st.format('E')=='Sun') { count=count+1; } st=st.addDays(1); } } } }
In the above code, how can i add count to variable et?
Regards,
Devendra S
Datetime dtStartDate=system.today();
Date dtDueDate;
integer DueDate=5;
integer jCount=0;
while(true){
if(dtStartDate.format('E')!='Sat' && dtStartDate.format('E')!='Sun'){
jCount=jCount +1;
if(jCount>DueDate){
break;
}
system.debug('jCount======' + jCount);
system.debug('==========' + dtStartDate);
system.debug('===========' + dtStartDate.format('E'));
dtStartDate=dtStartDate.addDays(1);
}else{
system.debug('==========' + dtStartDate);
//system.debug('===========' + dtStartDate.format('E'));
dtStartDate=dtStartDate.addDays(1);
continue;
}
}
system.debug('============' +dtStartDate);
Please see the above logic it will help you.
All Answers
Datetime dtStartDate=system.today();
Date dtDueDate;
integer DueDate=5;
integer jCount=0;
while(true){
if(dtStartDate.format('E')!='Sat' && dtStartDate.format('E')!='Sun'){
jCount=jCount +1;
if(jCount>DueDate){
break;
}
system.debug('jCount======' + jCount);
system.debug('==========' + dtStartDate);
system.debug('===========' + dtStartDate.format('E'));
dtStartDate=dtStartDate.addDays(1);
}else{
system.debug('==========' + dtStartDate);
//system.debug('===========' + dtStartDate.format('E'));
dtStartDate=dtStartDate.addDays(1);
continue;
}
}
system.debug('============' +dtStartDate);
Please see the above logic it will help you.
Thanks a lot Kritin.
Cheers,
Devendra S