I have two date fields called
Start Date and
I am looking for validation rule where I need to give error message if
Start Date is less than
Please guide me in this.
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.Sign up to join this community
I totally agree with @mast0r and @sfdc_ninja to use a validation rule if possible.
A possible reason not to use SF validation rules could be, that you would have to submit the page and then receive an error message, if the defined criteria is not met. Validation Rule is still best practice, but from the UX perspective optimizable.
If you really want to go with JS I assume you have skills in JS and you use jquery. Otherwise you have to adapt.
The challenge doing it in JS is, that your users might use different locales, so your date as String must be converted into a timestamp. Depending on what locales you have, you need to search for an appropriate convert function for that, e.g.
The strategy would be to bind a handler to either onchange or onkeyup at both of the input fields, convert both strings, do the math and provide feedback to the user.