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
David VaudreuilDavid Vaudreuil 

Validation Rule to prevent a date being entered that's less than 24 hours notice

Hi Ladies and Gents-

I have a requirement for a custom object (Catering Requests) that I'm running into issues with.  I want to create a validation rule that will prevent a user from entering a date for their requested catering delivery if it is less than 24 hours notice.  So, if the current system time is 5:00 pm and the requested catering date = Tomorrow at 9:00am I want to throw an error.  Any ideas on how to create that formula?  The custom field is a date/time field called Meeting_Date__c.  

Thanks!
Best Answer chosen by David Vaudreuil
SalesFORCE_enFORCErSalesFORCE_enFORCEr
Just use (Meeting_Date__c - Now())*24  < 24

All Answers

Prateek Singh SengarPrateek Singh Sengar
Hi David,
You can use the NOW() function for getting the current time. You validation will look something like

NOW() - Meeting_Date__c < 1.0

Please note that this formula is assuming that you and your users are in same timezone. In case the timezone is different you need to consider that in your calculation as well.
 
SalesFORCE_enFORCErSalesFORCE_enFORCEr
Just use (Meeting_Date__c - Now())*24  < 24
This was selected as the best answer
David VaudreuilDavid Vaudreuil
Thanks Shalabh_enFORCEr, that was the formula that I needed!
Margaret BraunMargaret Braun
This only works if the field is date/time.  I need this to work for just date.