I have a requirement wherein the user enters a data and if the date is more than 30 days then I show a validation error msg in lightning component. Below is the code I have done

<aura:attribute name="todayDate" type="date" description="date" default="" />
<lightning:input type="date" aura:id="IssuedDate" 
name="IssuedDate" label="Issued Date to" max="{!v.todayDate}" 
messageWhenRangeOverflow="Service To Date cannot be greater than 30 days the current date" />

In the Load event of lightning component I am doing as follows:

var todayDate = $A.localizationService.formatDate(new Date(), "YYYY-MM-DD"); 

But its not working as expected. Please let me know.

1 Answer 1


Why don't you use the standard valid rules in object manager? Create a new rule which is true when (issuedDate - Date.today() > 30), and set the error message to "Service To Date cannot be greater than 30 days the current date". That should work well when user subimt the form and got the error message which showed in the lightning-messages part or the field part based on your selection.

  • I am using javascript to handle this, I am not storing anything in backend, Commented Apr 9, 2021 at 6:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .