Requirement:
I have one date field called “Billing date” and one Number Field called “Billing Delay”. I want to update one Date field “DueDate” which computes “Billing date”+”Billing Delay”. While Computation It will Exclude the Saturday and Sunday!

Simple solution:

    for(BEV_BillingEvent__c BillingEvent:lstBillingEvent) 

{

    Datetime dt = DateTime.newInstance(BillingEvent.Billingdate__c, 3, 3, 3,0);
    //system.debug('dt** = '+ dt);

        for (Integer i = 1; i <= BillingEvent.BillingDelay__c;) {
          dt = dt.addDays(1);
          system.debug('dt = '+ dt+dt.format('EEE'));
          if(dt.format('EEE') != 'Sun' && dt.format('EEE') != 'Sat') i++;
        }
}

Advertisements