Skip to main content
I'm working on a trigger where i need to convert month name to integer value and i dont want to hard code like 'jan' = 1. Plz suggest.
6 answers
  1. Feb 26, 2016, 7:07 AM
    DateTime d = datetime.now();

    Integer count = 1;

    Integer dtMonth = 0;

    while (count < 13) {

         String monthName = d.format('MMMMM');

         monthName = monthName.substring(0,3);

          If(monthName == 'Compare your picklist value'){

                dtMonth = d.month();

                System.debug(dtMonth);

                break;    

         }

         else{

             d = d.addMonths(1);

             count++;

         }

    }       
0/9000