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
KD9500KD9500 

Date Methods

Hi,
 
I am trying to use the date method to modify a date but am unable to do so. The details are
Position is a custom object 
Opendate is a field with date data type
Count is a field with number date type
Closeddate is a field with date data type
I am trying to calculate the closedate from the Opendate and Count but i am not able to do so. The code is a follows

double c = position.Count__c;date mydate = date.valueof(position.Opendate__c);date newdate = mydate.adddays(c);position.Cdate__c = newdate;

If I replace the variable c with a constant number as 1 or 2, it performs the operation properly. I am unable to pass the value of Count there. How can i get this done.
 
Thanks
KD 

 

Best Answer chosen by Admin (Salesforce Developers) 
Michael_KahleMichael_Kahle

Hi KD9500,

 

the Method 'Date.addDays()' requires an Integer, but your Variable 'c' has the type double.

Try the following code :

 

 

position.Cdate__c = position.Opendate__c.addDays(Integer.valueOf(position.Count__c));

 

 

 

All Answers

Michael_KahleMichael_Kahle

Hi KD9500,

 

the Method 'Date.addDays()' requires an Integer, but your Variable 'c' has the type double.

Try the following code :

 

 

position.Cdate__c = position.Opendate__c.addDays(Integer.valueOf(position.Count__c));

 

 

 

This was selected as the best answer
KD9500KD9500

Thanks Michael..
 
Your option to change the value to integer worked. But I was not able to convert the double to integer, I changed 'Count__c' data type to string and then changed it to integer, it worked properly

 
Thanks again for the suggestion.
 
KD