function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
shiv kumar 48shiv kumar 48 

Events between to particular time

I have queried all the events in salesforce in a list now i want to loop through that list . if the startdate of event is between 12:00 AM to 1:00 PM i want to store in separate list ? how can i do it ?
Best Answer chosen by shiv kumar 48
Nithesh NNithesh N
Hi Shiv, Try this
 
List<Event> selectedEvents = new List<Event>();

for(Event e: allEvents) {
    
     DateTime startTime = e.StartDateTime;
    
     if((startTime.hour() >= 0) && (startTime.hour() <= 13)) {        
        selectedEvents.add(e);
    }
}

Please mark this solution as Best Solution to mark this forum as solved if it solves your question.

Best,
Nithesh.