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
Arun Deepan LJArun Deepan LJ 

Date time Difference

Hi,
In a custom object, I have two DateTime fields such as From Time and To Time. It is provided to specify the time shift interval such as morning 9.00 Am to Evening 2.00 Pm, and another shift 2.00 Pm to 10.00 PM.  But the problem, there is a shift which be like night today 10.00 PM to next day morning 7.00 AM. Based on the current execution time, it needs to select the exact record matching the shift. There can be multiple shift with multiple timings.

I am considering only the time part of both the fields. 
currently what I used is,
System.now() >  fromTime__c && system.now() < toTime__C

But in this, the shift from, night 10.00 PM to morning 7.00 AM cannot be matched with this.

 
Best Answer chosen by Arun Deepan LJ
Arun Deepan LJArun Deepan LJ
Hi, 
I mean to say about the logic, which I currently using. But actually I am separating(Extracting) the time part from the FromTime__c and ToTime__c and also from system.now(). I want to compare only with the time. I don't want to consider the date part. What ever the date, it does not matters. 

All Answers

sharathchandra thukkanisharathchandra thukkani
you mentioned considering only the time part of both the fields. 

But in the condition you are comparing with System.now() which is datetime field.

If you are comparing with Datetime field it should work please cross check.
Arun Deepan LJArun Deepan LJ
Hi, 
I mean to say about the logic, which I currently using. But actually I am separating(Extracting) the time part from the FromTime__c and ToTime__c and also from system.now(). I want to compare only with the time. I don't want to consider the date part. What ever the date, it does not matters. 
This was selected as the best answer