var fromdate=component.get("v.fromdate");
var toDate=component.get("v.enterdate");
var action=component.get("c.Difference");
action.setParams({
'fromdate':fromdate,
'toDate':toDate
});
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
var storeResponse = response.getReturnValue();
component.set("v.diff",storeResponse);
}
});
$A.enqueueAction(action);
Apex class:
@auraEnabled
public static Integer Difference(string fromdate ,string toDate)
{
Date dtfrom = date.valueOf(fromdate);
date enterdatedt = date.valueOf(toDate);
Integer diff=dtfrom.monthsBetween(enterdatedt);
return diff;
}
You can find the difference usng monthsBetween() function in the apex class as below:
Lightning component:
Lightning Controller:
Apex class:
Thanks.