+ Start a Discussion
shiv kumar 48shiv kumar 48 

Select all event records where startdatetime=enddatetime

List<Event> lstevt =[Select Subject,StartDateTime, EndDateTime,Description from Event  where StartDateTime!=null  and StartDateTime = EndDateTime]
        This is not working , i need to select all event records where startdatetime=enddatetime
Nithesh NNithesh N
Hi Shiv,

When you say, You want records where startdatetime = enddatetime.. That means they need to equal even by seconds. Not just Date, Hour and minutes. 

In most cases, This is not the case as seconds part of the time will be different. So, I would suggest you to compare Just Date, Hour and minutes.
 
List<Event> lstevt =[Select Subject,StartDateTime, EndDateTime,Description FROM Event 
                     WHERE StartDateTime != null AND EndDateTime != null];
List<Event> EqualList = new List<Event>();
for(Event E : lstevt){
  Integer MinuteDiff = (E.EndDateTime-E.StartDateTime)*24*60 ; 
              // gives total number of minutes from two datetime fields
  if(MinuteDiff == 0){
        EqualList.add(E);
   }

}


Let me know if it Works..

Best,​

Nithesh

GAURAV SETHGAURAV SETH

I need to create a event record for one hour slot thru apex code.
if I set event.startdatetime= date.addhours(8);


Adding 8 hrs to start time from 12. But calendar is showing 
slot for 3 AM. I already set all timezone as same.

can you please help?