Find your content:

Search form

You are here

SubString of a Date in Apex?


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.

Attribution to: AMM

Possible Suggestion/Solution #1

String myDate = o.CloseDate.year() + '-' + o.CloseDate.month() + '-' +;


String myDate = String.valueOf(o.CloseDate).SubString(0,10);

Attribution to: Sergej Utko
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content