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

Get Month,Year from Date


Could anybody tell me in one field in object, Date is stored. So i need to get record showing Month for that date . Is there any method like oracle i.e. to_char(StoredDate,MM) 


Or any method like Month(StoredDate).






You don't need Apex for this, you could just create a new Custom field of type Forumla and use this syntax : MONTH(date)


for more  :


Hello elmoussaoui,
I am trying To Get data In Query from Object In Apex code so don't need to work with Custom Field.

If you work with workbench Then below Is the query
SELECT RequestDate__c FROM Object_Name

Need To Get Month from that object Query

Sean TanSean Tan

If all you're trying to do is get the month / year from a Date in Apex this will work:


Object_Name item : [ SELECT RequestDate__c FROM Object_Name limit 1 ];

if (item.RequestDate__c != null)
	//Returns a numeric value representing the month (1-12)
	//1 = January
	Integer month = item.RequestDate__c.month();
	Integer year = item.RequestDate__c.year();		

Essentially you use the month() and year() method on the Date objects... see here for more information about the Date object in Apex:

Bhawani SharmaBhawani Sharma
Are you looking for something like this :
FROM Opportunity
ganesh thotaganesh thota
select id,CALENDAR_MONTH(createddate) from account group by CALENDAR_MONTH(createddate),id