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
steve456steve456 

CreatedDate =THIS MONTH

How do i give created date equal to this month in apex

 

if(CreatedDate=THISMONTH)

 

HOw do i give it in Apex

sfdcfoxsfdcfox
Inside a query:

SELECT ... FROM ... WHERE CreatedDate = THIS_MONTH

Inside apex code:

if(record.CreatedDate.month()==Date.Today().month()&&record.CreatedDate.year()==Date.Today().year()) ....

steve456steve456

Thanks but if  i want a particular month how do i get it 

 

CreatedDate = January

 

how could i do it

sfdcfoxsfdcfox
You can do something like this:

SELECT ... FROM ... WHERE CALENDAR_MONTH(CreatedDate)=1

See the SOQL reference for more details.
Swamy P R NSwamy P R N
Hi sfdcfox,

I need exactly  like your query as you mentionded above. But with small chagne, like

I want to compare two date fields by a dynamic soql. Query like :
CALENDAR_MONTH(CreatedDate) <=CALENDAR_MONTH(Time_Based_Mgmnt__r.End_Date__c)

It throws error like " expecting a colon, found 'CALENDAR_MONTH' " .

So please confirm me how to compare these two months. If i put the colon(:), getting another error " unexpected token: ( " . So please help me on resolving  this bug.