+ Start a Discussion
netTrekker_ADnetTrekker_AD 

Getting text name of Month out of a Date field instead of number

Ultimately I am wanting to create a custom field called PO Received Month which pulls the month of the PO Received Date field, but in text format, not number format.

 

Currently this is the formula I put in the Formula Text field but its spitting out "4" for April and "5" for May and I want it to read "April" and "May".

 

 

TEXT(( YEAR( PO_Received_Date__c )))

 Thanks in advance!

 

Best Answer chosen by Admin (Salesforce Developers) 
Steve MolisSteve Molis

Here you go

 

CASE(MONTH(LPO_Received_Date__c),
1, "January",
2, "February",
3, "March", 
4, "April", 
5, "May", 
6, "June",
7, "July",
8, "August",
9, "September",
10, "October",
11, "November",
12, "December",
"None")

 

 

All Answers

Steve MolisSteve Molis

Here you go

 

CASE(MONTH(LPO_Received_Date__c),
1, "January",
2, "February",
3, "March", 
4, "April", 
5, "May", 
6, "June",
7, "July",
8, "August",
9, "September",
10, "October",
11, "November",
12, "December",
"None")

 

 

This was selected as the best answer
netTrekker_ADnetTrekker_AD

Thank you sir. We still owe you, my boss has just been quite busy and pushing things back and back. I have not forgotten and will update you when I know more.

 

On a side note I have to admit that I acquired some Pliny the Edler via trade with a guy in Lafayette California and I must say you are right in your quest for it. Mighty fine stuff. Got a bottle of Blind Pig, Sculpin, and even a Stone RIS (we can get it here too but he threw it in) as well.

noreasternoreaster

This formula works great but when I group a report by the formula field I created and display it on a chart it has the months in alphabetical order instead of chronological order.  Any thoughts?

Steve MolisSteve Molis

Then you'd just use:

 

CASE(MONTH(PO_Received_Date__c),
1, "January",
2, "February",
3, "March", 
4, "April", 
5, "May", 
6, "June",
7, "July",
8, "August",
9, "September",
10, "October",
11, "November",
12, "December",
"None")

 

Steve MolisSteve Molis

Here you go...

 

PS.  You owe me a friggin' beer!

CASE(MONTH(LPO_Received_Date__c),
1, "1. January",
2, "2. February",
3, "3. March", 
4, "4. April", 
5, "5. May", 
6, "6. June",
7, "7. July",
8, "8. August",
9, "9. September",
10, "10. October",
11, "11. November",
12, "12. December",
"None")

 

noreasternoreaster
Thanks! I'll buy all the beer you want at dreamforce
noreasternoreaster

What is strange is it orders the months but puts October first.  How can I post a pic of the chart?

 

CASE(MONTH( CloseDate ),
1, "1. January",
2, "2. February",
3, "3. March",
4, "4. April",
5, "5. May",
6, "6. June",
7, "7. July",
8, "8. August",
9, "9. September",
10, "10. October",
11, "11. November",
12, "12. December",
"None")

 

 

Raju RathiRaju Rathi

have a look on below post 

 

http://salesforce.stackexchange.com/questions/8246/getting-format-for-date

 

Once you have Date in new format ,you can easily get the month name also . Please let me know if you need more info .

Trish Perkins 7Trish Perkins 7
Trying to use this formula in a custom field. I paste it into the enter formula page and when I hit, Check Syntax it starts throwing errors on the < or > or ( or ). The custom field is a text field and the date field is also custom. What could I be doing wrong? 

Thanks! 
Trish Perkins 7Trish Perkins 7
This is called the TrishPerkins Effect. Work for an hour to get something to work. Finally, admit your fallability and post a question. Within two minutes, you figure out the answer. To be the True Trish Perkins Effect, it has got to be impossible to find the answer BEFORE you post the question. 

Anyhow, I had left off the "None" - not sure why that made the diff, but all working now. Thanks, Steve et al! 
Rocks_SFDCRocks_SFDC
 Map<Integer,String> monthNameMap=new Map<Integer, String>{1 =>'January', 2=>'February', 3=>'March', 4=>'April', 5=>'May',
                                                                    6=>'June', 7=>'July', 8=>'August', 9=>'September',10=>'October',
                                                                    11=>'November', 12=>'December'};

System.debug(monthNameMap.get(Date_Field__c.month())); 
Lisa Lee-BanksLisa Lee-Banks
I created the formula field as a text field and see the month displayed as text instead of number.
Is it also possible to get the day and year to display but as number?
Here's what I need: May 29, 2018 from 29/05/2018
Nathan HincheyNathan Hinchey

Here's the documentation for formula fields: https://help.salesforce.com/articleView?id=customize_functions.htm&type=5


@Lisa Lee-Banks this will achieve what you want:

CASE(MONTH( Birthdate ), 
1, "January", 
2, "February", 
3, "March", 
4, "April", 
5, "May", 
6, "June", 
7, "July", 
8, "August", 
9, "September", 
10, "October", 
11, "November", 
12, "December", 
"None") 
& " " 
& TEXT(DAY( Birthdate)) 
& ", " 
& TEXT(YEAR( Birthdate))

Explanation:

CASE  is by far the most complicated part. CASE checks the value of the first argument (in this case MONTH( Birthdate) ), and then looks in the rest of its arguments, and find which one matches that: so, for instance, for a record where Birthdate = 29/05/2018, it would find which argument comes after 5 and that argument is "May", so it returns the text "May". The last argument is for what you get if the first argument doesn't match any of the other arguments.
NOTE: It is important to arrange your formula in a readable way. See how everyone has arranged it so that all the arguments are in pairs except the first and the last? If you don't do that it is very easy to lose track of your arguments.

MONTH( date ) checks the value of date and gives a number for the month (e.g. MONTH( Birthdate ) would return 5 if Birthdate = 29/05/2018)

& is the "concatenate" operator, meaning it combines texts together -- for instance, "May" & " " & "29" will return "May 29"

" " is there to say that we want a space -- the double quotes ("") mean that what is inside them is text -- it will just return that exact text.

TEXT( number ) will convert number to a text, (e.g., TEXT(29) would return "29"). We need to do this so that we can use the operator on it (because & can only be used on text, not numbers)

DAY( date ) will take the day number from date (e.g. DAY( Birthdate ) would return 29 if Birthdate = 29/05/2018)

YEAR( date ) you can probably guess what it does. It gives the four digit year number.


When functions are put together like this, it's usually best to think of them from the inside out. For instance:

TEXT(DAY( Birthdate)) is saying:

  1. Take the value of Birthdate -- for instance, 29/05/2018
  2. Apply the DAY() function to Birthdate -- so we get the number 29
  3. Apply the TEXT() function to that output -- so we get the text "29"


Like I started with, I really recommend you read the documentation of the various functions you can use! Formula fields are pretty powerful, and there are a lot of things you can do with it.

 

Lisa Lee-BanksLisa Lee-Banks
Thanks for the information. The example you provided worked perfectly. Client is so happy. Cheers!