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

Validate Time of Date/Time field

Thanks for help in advance!!
I have two fields on a custom object, startDate, endDate which a user inputs.
i.e. startDate: 3/24/2008  9:05 a.m.  endDate 3/26/2008 9:05 a.m.
notice that the start date is less than the end date but the times are equal, bad user..  This information is used to create multiple events for each day.. My users are having a hard time getting the timespan concept, and seem to keep doing this.
So how can i validate this to prevent this problem..
the simple
IF(Date_Start_Time__c >= Date_End_Time__c , true, false)
will not cut it here.. with the multiday issue.. I do not see anything in the validation that applies to time??
Thanks Again!!

Message Edited by Benjamin_Pirih on 03-20-2008 08:53 AM
KC-CRM AnalystKC-CRM Analyst

I'm sorry Benjamin, I may be misreading your post.

Did you say that the start date is greater than the end date?

I don't see that in your example.

On to the dirty work though.

First thing I want you to remember when doing any rules within Salesforce is that the IF() statement is partly implied by the coding which Salesforce uses.

When a formula evaluates to true, it will automatically trigger your rule.


IF(Date_Start_Time__c >= Date_End_Time__c , true, false)

will trigger the rule no differently than

Date_Start_Time__c >= Date_End_Time__c

This may seem very trivial but, it is very irritating when you receive the error "Your compiled formula contains 5,251 characters.  Maximum allowed compiled characters is 5,000."  This is one way to cut back on the use of characters.

I think that maybe you are looking for this instead:
DATEVALUE(Date_Start_Time__c) >= DATEVALUE(Date_End_Time__c)
What this does is determines a mathematical value for the DateTime in each field as a whole and compares their values against each other. This is built assuming you do not want identical values entered.
Thank you for your response and I do appreaciate the info.  You are correct the IF statement is not needed.
as for the example.. typo error less vs. greater.. it's been fixed..
In this example an event would be created for the 24,25,26 at 9:05 am to 9:05  thats right 3 events one for each day..
acttully this blows up, since an event timespan cannot be 0.. or should not..
I guess my real question is how do i get the Time portion of a date/time field for evaluation during validation?
so i can do something like this:
Or ( startDate >= endDate,  startDate__c.Time >= endDate__c.Time )
which is what i really want..
thanks again for the input!

Message Edited by Benjamin_Pirih on 03-20-2008 08:54 AM

Message Edited by Benjamin_Pirih on 03-20-2008 08:58 AM