Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to navigate the help pages associated with this, and I simply cannot find this simple reference. I want to show the first ten characters from a DateTime (CloseDate on Opportunity):


I just want the "2012-11-15" reference pulled out. What am I missing here? :-( Thanks for any help, all.

share|improve this question
up vote 2 down vote accepted
String myDate = o.CloseDate.year() + '-' + o.CloseDate.month() + '-' +;


String myDate = String.valueOf(o.CloseDate).SubString(0,10);
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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