I am trying to select a set of records in a batchable class that have expiration dates that are 7 or 30 days out. For the rest of the post I will only show 30 for brevity.
I tried setting my query string like:
String query = 'Select Id From Account Where Membership_Expiration_Date__c = ' + System.today().addDays(30);
Which doesn't work because it formats it this way in the query string:
I looked at the date literals and I didn't see anything to give me a certain day, other than today/yesterday/tomorrow, the rest all give ranges.
I also tried adding
DATE_ONLY(System.today().addDays(30)) and that errored out on me. Expecting a colon before
I finally ended up adding the following to my where clause:
Which works, but I feel like I am missing something obvious.
What is the best/easiest way to query records that are equal to the date n days from now?