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
Karthik PathaneniKarthik Pathaneni 

Adding days to a Date/Time field

Hi,

 

   I have a requirement where I have to add my custom Expiration Date with 90 days from submission Date field. but when I have created a workflow with the following field action it is updating the value of the expiration date with 90 days but an hour less.

 

Workflow Field Update Action : Submission_Date__c + 90

 

suppose my submission date is 10/10/2013 2:30AM'

 

then the expiration Date is getting updated as 01/08/2014 1:30AM whereas ideally it should get updated as 01/08/2014 2:30AM.

 

Please let me know any pointers in that.

 

Thanks,

Karthik

Dhaval PanchalDhaval Panchal
try below
Submission_Date__c = Submission_Date__c.addDays(90);

refer below link:
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_System_Date_addDays.htm
Karthik PathaneniKarthik Pathaneni

Hi Dhaval,

 

     I am using a workflow for the field update and not a class. AddDays(x) method is not working on the workflow. Please let me know how I can proceed in a workflow. 

 

     I have changed the formula to Submission_Date__c +90 + (60/1440) which will add an hour to the expiration date. But please let me know why exactly is (Submission_Date__c +90) not working.

 

Thanks,

Karthik

Karthik PathaneniKarthik Pathaneni

Hi Dhaval,

 

     I am using a workflow for the field update and not a class. AddDays(x) method is not working on the workflow. Please let me know how I can proceed in a workflow. 

 

     I have changed the formula to Submission_Date__c +90 + (60/1440) which will add an hour to the expiration date. But please let me know why exactly is (Submission_Date__c +90) not working.

 

Thanks,

Karthik

Dhaval PanchalDhaval Panchal
Hi,

I tried below example in workflow and it worked for me.

DATEVALUE( TEXT( CreatedDate ) ) + 90

I have created one date type field "Expiration Date" and updated it by adding 90 days to created date.

Here created date is of type dateTime so i have converted it to Date type and then added 90 days and it worked fine for me.
Karthik PathaneniKarthik Pathaneni
Hi Dhaval,
 
 I have updated the workflow's field update  as
  
DATEVALUE(TEXT(Submission_Date__c)) + 90
and got the following error. 
 
Error: Formula result is data type (Date), incompatible with expected data type (Date/Time).
 
 
Also, even when I am updating the field with Submission_Date__c + 90 it is updating the date correctly but issue is only with the time.. It is showing an hour less.
 
for example if the submission date is 10/10/2013 2:30AM 
the expiration field is getting updated as 01/08/2013 1:30AM
 
 
There is no concern for the date value, but the real concern lies with the time as mentioned by me earlier. Could you let me know why this is occuring?
 
Thanks,
Karthik
AuyonAuyon

Well, if its a datetime field it would require the field value to be returned as date/time rather than date type.

 

So there is a formula for doing this would be something like  (( (<number of hours>) * 60) + <number of mins> )/1440

 

So your fornula should be Submission_Date__c + (( (24* 90) * 60) + 0> )/1440

 

Thats it. I am sure this will solve your issue. If it does and if like my answer please mark it as solution and click the star to add kudos.

 

Karen Brown 39Karen Brown 39
I am tryying to do exactly this now but get syntax error

The formula expression is invalid: Syntax error. Found ')'
Jonathan MullerJonathan Muller
I know this is really old, but the 1-hour difference you are seeing is due to daylight savings being factored into the date/time.
Karen Brown 39Karen Brown 39
Hi Jonathan, yes and actually no that the clocks have changed it is working fine.

Thanks