+ Start a Discussion
nbknbk 

How to convert DateTime to Date format

Hi All,

 

I need to convert DateTime field  2011-03-21T11:54:45.000Z to Date Format. March 21, 2011

 

Thanks,

Krishna

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

Assuming your date/time field is called 'MyDT__c', you can use the format method as follows:

 

String formatted=MyDT__c.format('MMMM dd, yyyy');

 

All Answers

bob_buzzardbob_buzzard

Assuming your date/time field is called 'MyDT__c', you can use the format method as follows:

 

String formatted=MyDT__c.format('MMMM dd, yyyy');

 

This was selected as the best answer
BussBuss

Hi Bob,

 

i tried to get Date as March 20,2011 but while saving it showing error as can not have format('String') method.

 

while saving with My__c.format()- displaying date based on Locale like dd/mm/yyyy.

i want to know is there any way to get date format as 'DD MMM,YYYY'.i.e 20 Mar,2011.

if possibe, Pls can you explain how do i get that date format.

 

 

Rgds,

Buss