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
JaredPHJaredPH 

Please help newbie--days between date and datetime field?

I've got a trigger that needs to specify a picklist value based on the number of days between two fields, but one is a date and one is a datetime. I'm trying to use the date method to convert the datetime before using daysbetween, but can't figure out how to get it to work. I'm VERY new at triggers, so hopefully this should be straightforward....I just can't get it.

 

Trigger LateApp on opportunity(after update)
{
datetime dt1;
date dt2;
list<opportunity> opp=new list<opportunity>();
for(opportunity o : trigger.new)
{
dt1=trigger.new[0].Accepted__c;  *****do I add a .date here somewhere??****
dt2=trigger.new[0].Payment_ref__c;
if(dt1.daysBetween(dt2)+45 >= 45 || dt1.daysBetween(dt2)+45 < 75)
{
o.Payment_Plan__c ='Late1';
}
if(dt1.daysBetween(dt2)+45 >= 75 || dt1.daysBetween(dt2)+45 < 105)
{
o.Payment_Plan__c ='Late2';
}
if(dt1.daysBetween(dt2)+45 >= 105)
{
o.Payment_Plan__c ='Late3';
}
opp.add(o);
}
update opp;
}

SeAlVaSeAlVa

Try the following

 

date dt1;
// ... //
dt1 = trigger.new[0].Accepted__c.date();


// or you can also cast it before calling daysBetween by ...
dt1.date().daysBetween(dt2()) // with dt1 as datetime 

 Regards