You can add a couple clauses:
SELECT Date__c FROM Object__c
WHERE Date__c < TODAY
ORDER BY Date__c DESC
LIMIT 1
- The
ORDER BY
clause makes sure you get the most recent result first. - The
LIMIT
clause makes sure you only get one result.
So if you wanted a method that returns just the Date
value it would look like:
public static Date getMostRecentXBeforeToday()
{
return [/*query*/].Date__c;
}