You need to sign in to do that
Don't have an account?
Satyavathi Polepally
get current month and use it in soql query
Hi
I want to get the current month from picklist field and use that current month in soql query in a batch class. I have written the following code and its not working.
Any help is appreciated.
String month = Product.Month__c.month();
Set<String> ple = new Set<String> {'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'};
String query = 'Select Id, Name, Month__c from Product where CALENDAR_MONTH(Month__c) = :month';
I want to get the current month from picklist field and use that current month in soql query in a batch class. I have written the following code and its not working.
Any help is appreciated.
String month = Product.Month__c.month();
Set<String> ple = new Set<String> {'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'};
String query = 'Select Id, Name, Month__c from Product where CALENDAR_MONTH(Month__c) = :month';
Check if you can read the month as a integer and then do the comparison
month()
Returns the month component of a Date (1=Jan).
Signature
public Integer month()
Return Value
Type: Integer
Example
view sourceprint?
1date myDate = date.newInstance(2004, 11, 21);
2Integer month = myDate.month();
3system.assertEquals(11, month);
Regards,
Krishna Avva
Integer Month = Date.Today().Month();
Hope it helps!
String Month = String.valueOf(System.now().month());
And use this in the batch query.