Skip to main content Trailblazer Community 在 2025-2-1 至 2025-2-2 之间将不可访问。请相应地安排您的活动。
I have basically 3 dates startdate , enddate and userdate .  

Question : i have a batch which should pick the records  where the Userdate SHOULD NOT fall in between the Range of startdate and enddate .

can anyone please modify my snippet of code.

my code snippet: 

Date userDate =Date.newInstance(2018, 11, 31); 

Date startdate =Date.newInstance(2017, 1, 31); 

Date enddate =Date.newInstance(2017, 12, 31); 

if(userDate < startDate  &&   endDate  > userDate  )

{   

system.debug('True');

}else

 {

 system.debug('false');

 }
2 个回答
  1. 2018年8月24日 09:33
    Hi,

    Trying using below method and let us know if it works.

     

    public boolean isDateInRange(Date startDate, Date endDate, Date userDate){

    // Assuming endDate is always greater than startDate

    if(userDate < startDate){ // less than start date, not in range

    return true;

    }else if(userDate > endDate){ // greater than end date, not in range

    return true;

    }else if(userDate > startDate && userDate > endDate){ // greater than both

    return true;

    }else if(userDate > startDate && userDate < endDate){ // in range

    return false;

    }

    }

     
  2. 2018年8月23日 05:21

    Date userDate =Date.newInstance(2018, 11, 31);

    Date startdate =Date.newInstance(2017, 1, 31);

    Date enddate =Date.newInstance(2017, 12, 31);

    if(userDate < startDate || endDate > userDate )

    {

    system.debug('True');

    }else

    {

    system.debug('false');

    }

     
0/9000