function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ 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 :-/Steve :-/

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 :-/Steve :-/

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 :-/Steve :-/

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 :-/Steve :-/

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!
Anjali MalhotraAnjali Malhotra
Wow! You are genius Nathan. The formula saved my days of frustration. 
 
mikechayesmikechayes
Here is an easy way

String CurrentMonth = TodaysDate.format('MMMM');
 
Gabriel LopesGabriel Lopes
The DATEVALUE get the value of month:

CASE(MONTH(DATEVALUE(CreatedD)),
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")
Michael ShiresMichael Shires
Nathan Hinchey, is there a way using the case fustion you laid out above, to return the birthdate value instead of 1s and zeros? 

I am trying to creat a customer birthday report by branch, and your case funtion worked great. I was just wanted to retunr the birthday vs a 1 or 0 so the user does have to drill down or search for the accoutn to find the acctual day. 

Thoughts? 
Steven Truong 18Steven Truong 18
SteveMo, where do we send you beers?
Ashok Kumar 690Ashok Kumar 690
Hi @SteveMo__c,

Your answer worked for creating month field, Now i have similar new requirement asking to use same field for 2 date fields
User-added image
Can you help me on this formula.

Thanks,
 
Jeane MoyaJeane Moya

ok, this only partly solves my formula.  The syntax gets screwy when I put case as the second function.  I want my dates to read, for example,

2 October 2022 

It is a requirement on some reporting that we put dates in this format.  the solution that Nathan gives above works great for showing the date as October 2, 2022.  But how can I edit the formula without getting all sorts of errors...  This is what I have, and it tells me incorrect syntax...

TEXT(DAY(Contact__r.Birthdate)) & " " & CASE(MONTH( Contact__r.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(YEAR(Contact__r.Birthdate))
 

Dolly . 7Dolly . 7
Hi everyone,

I have added the transformation in the recipe and numbered 1-April to start from the fiscal month. But while applying the global filter on the month field; the months are not ordered in ascending order. display as 1-April then 10-January, 11-February, 12, 2,3,4.. so on

Please help how can we sort the global filter.

Thank you in advance.