Monday, September 22, 2014

Getting today date in some other format !

I recently came across a requirement in which date was requited in a format of MM/DD/YY but the default format is given as '2014-09-22 00:00:00'
Code to change date format 
Date d = Date.Today();
       String MonthValue = String.valueof(Date.Today().month());
       if(MonthValue != null && MonthValue != '' && MonthValue.length() == 1){
         MonthValue = '0'+MonthValue;
       }
       String DateValue = String.valueof(Date.Today().day());
       if(DateValue != null && DateValue != '' && DateValue.length() == 1){
         DateValue = '0'+DateValue;
       }
       String Last_Date_Modified = String.valueof(Date.Today().year())+'-'+MonthValue+'-'+DateValue;
       string StringToBePassed = 'Last_Date_Modified='+Last_Date_Modified;

No comments:

Post a Comment