1
String myDate = Datetime.now().addDays(14).formatGmt('MM/DD');
System.debug('mydate'+myDate);

Works fine when I execute from Developer console, today is 24 Jan and it prints 02/07 which is correct.

But when I execute in a Batch class it prints 02/38 which is wrong, why ?

2

You're not using the right format for days. From SimpleDateFormat:

D Day in year
d Day in month

So it sounds like you want to use MM/dd.

  • Thank you it was found and resolved. I updated it in the salesforce forum already. developer.salesforce.com/forums/… – Sachin Kumar Jan 27 '17 at 4:44
  • @SachinKumar If this answer addressed your problem, please consider accepting it by clicking on the check mark/tick to the left of the answer, turning it green. This marks the question as resolved to your satisfaction, and awards reputation both to you and the person who answered. If you have >= 15 reputation points, you may also upvote the answer if you wish. There is no obligation to do either. – Adrian Larson Jan 27 '17 at 4:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.