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
johnn devjohnn dev 

how to get data and month from a salesforce field

how to get data and month from a salesforce field

EXAMPLE: I need to get month and day from the "date" field, but the date field is filled with day/month/year example 05/15/2022. but I just want it to return the day and month from this field and I don't want it to return the year what is the formula for this apex class

PriyaPriya (Salesforce Developers) 

Hi Johnn,

If you want to use the logic in apex class then use this way :-

Integer dtMonth = c.Contract_Start_Date__c.month();
 
The method ".month()" returns an integer, so if your date is 11/11/2012, it will return you '11'.  To get the Month Name, write some logic that returns you the month name when you pass the month number to it.

If this help, please mark it as best answer so that it can help others.

Regards,

Priya Ranjan
Salesforce

johnn devjohnn dev
I need to remove the year, just have to restore example: 12/11. however my field has the complete date and I need to return only date and month
johnn devjohnn dev
my query where I get date and month String Ldate = (string) lmapdata.get('date');