You need to sign in to do that
Don't have an account?
Vinita Kumari
How to month in number from "MMM" format?
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.
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++;
}
}
All Answers
If this wont help you out just provide me the exact format of date which you currently have in your trigger.
https://developer.salesforce.com/forums/?id=906F00000008ugkIAA
There is no date format.
I have picklist of 'Jan', 'Feb', 'Mar',etc from which I need to get the month in number.
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++;
}
}
{
Map<String, String> monthsMap = new Map<String, String>
{
'January' => '01',
'February' => '02',
'March' => '03',
'April' => '04',
'May' => '05',
'June' => '06',
'July' => '07',
'August' => '08',
'September' => '09',
'October' => '10',
'November' => '11',
'December' => '12',
'Jan' => '01',
'Feb' => '02',
'Mar' => '03',
'Apr' => '04',
'Jun' => '06',
'Jul' => '07',
'Aug' => '08',
'Sep' => '09',
'Oct' => '10',`
'Nov' => '11',
'Dec' => '12'
};
return(monthsMap.get(monthName));
}