+ Start a Discussion
Monishan MMonishan M 

Hi, Can you please let me know how to find if the date diff between two dates is exact 60 days

Hi,

I need to find difference between a date field and todays date and check if its equal to exact 60 days.

I used the below statement in code bt its throwing error as 
"Invalid field 60 for object "
Statement:
if(60==Integer.ValueOf(Date.valueof(startdate).daysBetween(System.today())))

Could you please let me know how to achieve this?

Thanks
 
AnudeepAnudeep (Salesforce Developers) 

Per this documentation, If you want to find how many days there are between two dates, you should use something like this 
 
TODAY() - DATEVALUE(CreatedDate)

Can you try doing If(60==TODAY() - DATEVALUE (startdate))?

To find the number of days between two dates, date_1 and date_2, just subtract the earlier date from the later date: date_1 — date_2

Also, see this help article 

If you find this information helpful, please mark this answer as Best. It may help others in the community. Thank You!

Anudeep
Vanisha_GuptaVanisha_Gupta
Hi,

Please have a look:
1) You can create a formula field to check : 
IF(  DATEVALUE(ClosedDate ) - TODAY() = 60,True, False)

2) Using Apex Code:
Contact c=[Select Id,CreatedDate from Contact LIMIT 1];
DateTime d1=c.CreatedDate;
Date d=date.newInstance(d1.year(),d1.month(), d1.day()); //first, converted DateTime to Date
Integer val=d.daysBetween(System.Today()); //subtract
if(val==60){   //compare
    System.debug('true');
}

Let me know if it works!