You need to sign in to do that
Don't have an account?
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;
}
Try the following
Regards