+ Start a Discussion
SabrentSabrent 

unary increment/decrement can only be applied to numeric expressions

I am getting and error 'unary increment/decrement can only be applied to numeric expressions'

Any other way to iterate over Date or DateTime? 

 

Date d1 = newTsscActivity.Start_Date_Time__c;
Date d2 = newTsscActivity.End_Date__c;
         	
   //DateTime dt1=DateTime.newInstance(d1, Time.newInstance(0, 0, 0, 0));
  //DateTime dt2=DateTime.newInstance(d2, Time.newInstance(0, 0, 0, 0));
         	
   for (date d=d1; d<=d2;d++){
         		
        DateTime dt1=DateTime.newInstance(d, Time.newInstance(0, 0, 0, 0));
         	
        String dayofweek = dt1.format('EEE');
         		
         		        		
    } 

 

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Andrew WilkinsonAndrew Wilkinson

Use the date methods.

 

It would be 

 

d.addDays(1)

 

instead of d++

All Answers

arizonaarizona

Try converting to date type.

Andrew WilkinsonAndrew Wilkinson

Use the date methods.

 

It would be 

 

d.addDays(1)

 

instead of d++

This was selected as the best answer
kirkevonphillykirkevonphilly

I used what Andrew recommended in my response to your other thread in a do/while loop:  http://boards.developerforce.com/t5/Apex-Code-Development/How-many-Fridays-between-2-dates/td-p/543407

SabrentSabrent

Thanks Andrew and kirkevonphilly

 

Hoenstly I didn't mean to double post the issue. I was trying two different approaches to the same problem and  came across two disctinct questions. 

 

I tried kirkevonphilly.  solution in the post (  http://boards.developerforce.com/t5/Apex-Code-Development/How-many-Fridays-between-2-dates/td-p/5434...) but hitting TOO many script error. 

 

 

Your help is much appreciated!!!

SabrentSabrent

Thanks for your help Andrew.  My problem's solved.  very much appreciated!!!!