You need to sign in to do that
Don't have an account?
willing
I need to add yeare, months and days to a date
I have a situation where I have to add years, months or days based on the values in a variable . Here is what I am doing.
the variables used have these values
time_cov = 1
ST[0].SVMXC__Unit_of_Time__c == 'Years' is true
so it should add 1 year to the date t . But it does not add anything
It does go in the if - statement and system.debug statement does get executed.
date t = date.valueOf(WR.SVMXC__Start_Date__c);
if (ST[0].SVMXC__Unit_of_Time__c =='Years' )
{ t.addYears(time_cov) ;
system.debug(t);
}
else if (ST[0].SVMXC__Unit_of_Time__c =='Months')
{ t.addMonths(time_cov) ;}
else if (ST[0].SVMXC__Unit_of_Time__c =='Days')
{ t.addDays(time_cov) ;}
else if (ST[0].SVMXC__Unit_of_Time__c =='Weeks')
{ t.addDays(time_cov * 7) ;}
Please let me know if I am doing anything wrong
Any help is appriciated
the variables used have these values
time_cov = 1
ST[0].SVMXC__Unit_of_Time__c == 'Years' is true
so it should add 1 year to the date t . But it does not add anything
It does go in the if - statement and system.debug statement does get executed.
date t = date.valueOf(WR.SVMXC__Start_Date__c);
if (ST[0].SVMXC__Unit_of_Time__c =='Years' )
{ t.addYears(time_cov) ;
system.debug(t);
}
else if (ST[0].SVMXC__Unit_of_Time__c =='Months')
{ t.addMonths(time_cov) ;}
else if (ST[0].SVMXC__Unit_of_Time__c =='Days')
{ t.addDays(time_cov) ;}
else if (ST[0].SVMXC__Unit_of_Time__c =='Weeks')
{ t.addDays(time_cov * 7) ;}
Please let me know if I am doing anything wrong
Any help is appriciated
Is time_cov an integer?
are you sure your date t is the value you think it is before the addYears? Have you tried putting a debug on t before the addYears statement?
Date t ;
if (ST[0].SVMXC__Unit_of_Time__c =='Years')
{t = WR.SVMXC__Start_Date__c.addYears(time_cov) ;
// system.debug(t);
}
I think the problem was your date.ValueOf() in the original. That doesn't operate on a date value.