+ Start a Discussion
DJP1SDJP1S 

Getting the date portion of the datetime field LastModifiedDate

If I write a string like this: 

 

priorityList += '- ' + writePriority[i].CreatedBy.Name + ' - ' + writePriority[i].LastModifiedDate + ': ' + writePriority[i].Priority_Notes__c;

 What would be the best way to get the modified date to only display 2012-09-14, without the time following?

Best Answer chosen by Admin (Salesforce Developers) 
SFFSFF

I would suggest instead:

 

priorityList += '- ' + writePriority[i].CreatedBy.Name + ' - ' + 
   writePriority[i].LastModifiedDate.date().format() + 
   ': ' + writePriority[i].Priority_Notes__c;

 Good luck!

All Answers

SFDC-SDSFDC-SD

        

Try something like this to format.

 

*public static Date StringToDate(String s){
      //XML Date String is in the format dd/mm/yyyy
      String[] stringDate = s.split('-');
      Integer d =  Integer.valueOf(stringDate[0]);
      Integer m = Integer.valueOf(stringDate[1]);
      Integer y = Integer.valueOf(stringDate[2]);
      return date.newInstance(y,m,d);
}  

SFFSFF

I would suggest instead:

 

priorityList += '- ' + writePriority[i].CreatedBy.Name + ' - ' + 
   writePriority[i].LastModifiedDate.date().format() + 
   ': ' + writePriority[i].Priority_Notes__c;

 Good luck!

This was selected as the best answer
DJP1SDJP1S

Thank you, John. That works great!