+ Start a Discussion
Nikhil Singhal 22Nikhil Singhal 22 

Current Date in SOQL


I am beginner in Salesforce and learning SOQL and SOSL right now. In a problem staement, I want to compare month of LastModifiedDate with the month of current date but unable to do. Can anyone please help?
Sandesh D GanjareSandesh D Ganjare
Hi Nikhil,

You can create a formula field and use it.
ref: https://trailhead.salesforce.com/content/learn/modules/point_click_business_logic/formula_fields

Nikhil Singhal 22Nikhil Singhal 22
Hi Sandeep,

Thanks for answering. Below is my problem statement :
Get all Leads Where ModifiedDate is in current month

For this statement, what would be the SOQL query?
Malika Pathak 9Malika Pathak 9

Hi Sandeep,

Date d=system.today();
Date modifiedDate=Date.newInstance(1960, 2, 17);

If you find this helpful mark it as the best answer.
AnudeepAnudeep (Salesforce Developers) 
Sandeep - Get all Leads Where ModifiedDate is in the current month
SELECT Id, Name, CreatedDate FROM Lead WHERE LastModifiedDate = THIS_MONTH

If the above query gives you any errors, you should try something like this
Date startOfMonth = Date.today().toStartOfMonth(); 

Date startOfNextMonth = startOfMonth.addMonths(1); 

List<CustomObj__c> list = [SELECT Name FROM CustomObj__c WHERE Expense__Date__c >= :startOfMonth AND Expense_Date__c < :startOfNextMonth];

NOTE: The code provided is an example. You'll need to review and make modifications for your organization.

Let me know if this helps, if it does, please mark this answer as best so that others facing the same issue will find this information useful. Thank you