+ Start a Discussion

add minutes usage

field name casedate =  '2011-05-16T18:30:08.923-07:00'

how do i add minutes to this field casedate, example i want to add 200 mintues or sometimes its -420 minutes, how do i do that?
I know there is a function called addMinutes(Integer)
sorry value is '2011-05-16T18:30:08.9230Z'
If you want to add to the same field, then you would need to use an Apex Trigger, and update the value of this field. You can use Apex Function addMinutes. 

If you don't want to write code, then you can create a forumula field, but there is no addMinutes function in formula, so you would need to extract minutes, add value to them and create a date-time value... could be complex to create. 
Thanks i did this in apex however i get wrong time.

at db level time value in field cas.GMTcallback__c (GMT time) is 2014-11-07T01:00:00:000Z

Result for code below is following:
cas.Email_Template_GCS_CallBack_Time__c = 2014-11-06 10:00 AM

However value of result should be 11/6/2014 5:00 PM (420 minutes is -7 hours, i am using PST time to calcuate and hence -420)

Code used:
               DateTime dt = cas.GMTcallback__c;
               DateTime myDT = dt.addMinutes(-420);
               String myDate = myDT.format('yyyy-MM-dd hh:mm a');
               cas.Email_Template_GCS_CallBack_Time__c = myDate;

What am I doing wrong here?

1. What is your current user's timezone ?
2. Is cas.GMTcallback__c a DateTime type ?
3. If you debug and print cas.GMTcallback__c in your class / trigger, what are you getting ?