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
Satyavathi PolepallySatyavathi 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';

 
KrishnaAvvaKrishnaAvva
Hi satyavathi,
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
Shobit GuptaShobit Gupta
Please try the below snippet.
Integer Month = Date.Today().Month();

Hope it helps!
Satyavathi PolepallySatyavathi Polepally
Finally found the answer to my query. 
String Month = String.valueOf(System.now().month());
And use this in the batch query.