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
willingwilling 

I want to add years , months, 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
RickyGRickyG
The code indicates you are not using the Force.com Builder.  What language is your code in?  I will move this message to a more appropriate discussion board based on the language.