+ Start a Discussion
Mitch MorrisonMitch Morrison 

Apex compare Event EndDateTime to Today

Trying to compare an Events EndDateTime to today's date. Obviously, I need to convert EndDateTime to something that can be compared. I tried:

DateTime dt = Ev.EndDateTime();
Date EndDate = date.newInstance(dt.year(), dt.month(), dt.day());

And got this error: Method does not exist or incorrect signature: void EndDateTime() from the type Event

I want to get the difference between the Event date and today's date (so subtraction is needed). Thanks for any help!
@anilbathula@@anilbathula@
Hi Mitch,


Try this     : 
DateTime dt=Ev.EndDateTime-System.today();
 
I think you are refering to the Events EndDateTime field.

Thanks
Anil.B
Ajay K DubediAjay K Dubedi
Hi Mitch,

Try changing your code as below :

Event e=[Select EndDateTime  From Event where whatid=:tsk.whatid and what.type = 'Account' and EndDateTime <=:system.now()];

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi