You need to sign in to do that
Don't have an account?
How do I select based on Date is THIS MONTH?
String query = 'SELECT Id,Run_Maintenance_Calculator_del__c FROM Account WHERE PIN_Code__c != null';
I like to add
AND Custom_Date__c = THIS MONTHbut cannot figure it out. I appreciate the help.
All Answers
Please try below code and let me know.
Integer mnth = System.Today().MOnth();
Integer yr = System.Today().Year();
String query = 'SELECT Id,Run_Maintenance_Calculator_del__c FROM Account WHERE PIN_Code__c != null AND CALENDAR_MONTH(CreatedDate) = mnth ANDCALENDAR_YEAR(CreatedDate) = yr ';
Best Regards,
-Vivek
Please try below code and let me know.
Integer mnth = System.Today().MOnth();
Integer yr = System.Today().Year();
String query = 'SELECT Id,Run_Maintenance_Calculator_del__c FROM Account WHERE PIN_Code__c != null AND CALENDAR_MONTH(CreatedDate) ='+ mnth +'and CALENDAR_YEAR(CreatedDate) ='+ yr ;
System.debug('query==>'+query);
List<Account> searchAccounts = Database.query(query);
Best Regards,
-Vivek
I had tried THISMONTH but never thought to put the underscore in the middle. That link had all the documentation I needed.
Thanks!
Please check below link for all date variable
https://help.salesforce.com/HTViewHelpDoc?id=custom_dates.htm&language=en_US (https://help.salesforce.com/HTViewHelpDoc?id=custom_dates.htm&language=en_US)
Please check below link for date function in salesforce
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_date_functions.htm
Some example for you. I hope that will help you
Please more example in below link:-
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_dateformats.htm
Please try below query:-
Please let us know if this will help you.
Thanks
Amit Chaudhary