+ Start a Discussion
ManjeetManjeet 

Date Format issue ????

Hi All,


DateTime myDate  = DateTime.newInstance(2010,10,10);

 

String strDate = myDate.format('yyyy/mm/dd');

 

does not give expected result '2010/10/10' .Rather it give '2010/00/10' .

 

?

plz let me know where i am wrong or the format method has some  flaw .

 

Best Answer chosen by Admin (Salesforce Developers) 
rmehrmeh

Hi Manjeet,

 

Please do the following:

 

 

DateTime myDate  = DateTime.newInstance(2010,10,10);
String strDate = myDate.format('yyyy/MM/dd');
System.debug('strDate=========' +strDate);

 This will work.

 

All Answers

rmehrmeh

Hi Manjeet,

 

Please do the following:

 

 

DateTime myDate  = DateTime.newInstance(2010,10,10);
String strDate = myDate.format('yyyy/MM/dd');
System.debug('strDate=========' +strDate);

 This will work.

 

This was selected as the best answer
ManjeetManjeet

Thanks a lot .it is working for me .

But Even apex is case insensitive then what was the problem with small 'mm' ?

rmehrmeh

Hi Manjeet,

 

You are right, that apex is case insensitive.

but the date formats are case sensitive.

JimRaeJimRae

In regards to the date format, the lowercase "mm" is used to indicate minutes, and the uppercase "MM" is used to indicate months, that was your issue.  By default, you were setting hours, minutes and seconds to all zeros, which is what you saw with your string format.

rmehrmeh

Yes, you are absolutely right.

I miscommunicated it.