0
votes

I am able to evaluate today's date using:

String timeframe = DateTime.newInstance(Date.today(), Time.newInstance(0, 0, 0, 0)).format('yyyy-dd-MM');

But I need to add days to this. So I want:

String timeframe = DateTime.newInstance(Date.today()**.addDays(10)**, Time.newInstance(0, 0, 0, 0)).format('yyyy-dd-MM');

query += ' and (created_date__c <= ' + timeframe + ')';

But am receiving this error: line 1:392 no viable alternative at character '2'

I also tried:

DateTime refDate1 = DateTime.newInstance(System.today().year(), System.today().month(), System.today().day(), 0, 0, 0);

DateTime refDate2 = refDate1.addDays(-10);

query += ' and created_date__c <= '+ refDate1.date() + ' and created_date__c >= ' + refDate2.date();

Which throws: line 1:405 no viable alternative at character ' '

Please help!

1

1 Answers

0
votes

I resolved this using code I'd already tried, which makes me think there was something wrong with my soql string to begin with.

String timeframe = DateTime.newInstance(System.today().addDays(-10), 
Time.newInstance(0, 0, 0,0)).format('yyyy-dd-MM');

whereClause += ' and (';
whereClause += 'created_date__c >= ' + timeframe;
whereClause += ' OR sourced_date__c >= ' + timeframe;
whereClause += ' OR last_phone_bank_call_date__c >=' + timeframe; 
whereClause += ')';