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
@ M  Coder@ M Coder 

Userdate shouldnot be in range of StartDate and EndDate Ranges in apex saleforce

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');
 }
Raj VakatiRaj Vakati
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');
 }

 
Ravi Dutt SharmaRavi Dutt Sharma
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;
	}
	
}