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
OdedHarnivOdedHarniv 

String representation for Month of Date

Hi

 

I'm trying yo write code that generates a string which includes the Month e.g. January.

From the Date object I have the integer representing January (1) but I want the String.

I also wish this string will adopt to the relevant Language.

 

I know I can use Custom Labels and CASE statement but before I do that I want some help, maybe there is a better more native way to achive the same.

 

Thanks

 

 

Best Answer chosen by Admin (Salesforce Developers) 
SatgurSatgur

Assuming the date you are dealing with is DATE type object (& not DateTime), you could use below approach for fetching month value as January -

 

 

Date myDt = Date.parse('01/20/2011') ;
DateTime dtime = DateTime.newInstance(myDt.year(), myDt.month(), myDt.day()) ;
String target = dtime.format('MMMMMMMM ','GMT') ;

 

 

If you print the value of String variable ('target' in above example), you will get JANUARY.

 

Hope this answers first part of your question.

 

For converting this into Local language, I believe we have to leverage "Multi lingual" capability of the Salesforce. But haven't tried that myself yet. Hence can't provide a straight answer to that.

 

- Satgur

All Answers

SatgurSatgur

Assuming the date you are dealing with is DATE type object (& not DateTime), you could use below approach for fetching month value as January -

 

 

Date myDt = Date.parse('01/20/2011') ;
DateTime dtime = DateTime.newInstance(myDt.year(), myDt.month(), myDt.day()) ;
String target = dtime.format('MMMMMMMM ','GMT') ;

 

 

If you print the value of String variable ('target' in above example), you will get JANUARY.

 

Hope this answers first part of your question.

 

For converting this into Local language, I believe we have to leverage "Multi lingual" capability of the Salesforce. But haven't tried that myself yet. Hence can't provide a straight answer to that.

 

- Satgur

This was selected as the best answer
OdedHarnivOdedHarniv

Thank you this has worked now I just need to figure how to use the "Multi lingual" capabilities