how to validate future date( > today) in snippet

in my model i have a field like expected_start_date__c. this date should be future date. how to write snippet code for this validation. Thanks in advance

Hi raj

This is pretty simple. You just need to compare the two dates using common operators:

var today = new Date(), &nbsp; &nbsp; tomorrow = new Date();<br />tomorrow&#46;setDate(tomorrow&#46;getDate() + 1);<br />console&#46;log(today &gt; tomorrow); &#47;&#47;false<br />console&#46;log(today &lt; tomorrow); &#47;&#47;true<br />console&#46;log(today == tomorrow); &#47;&#47;false 

Try it out and play with it. Alter the script to fit your needs and you should be good to go.


my requirement for that field is , if that field is null or undefined or past date, then i want throw error to add the future date in if condition

if (Startdate === ‘’ || Startdate === null || Startdate === undefined ) {

            message: ‘Please Enter Expected start date and Expected date should be future date’,
            severity: ‘ERROR’

    return false;

raj, you need to get your salesforce date into javascript and then compare it to a new Date().
take a look at