I am working with an ASPxDateEdit
control and here is the code snippet:
<dx:ASPxDateEdit ID="dtPayDate" ClientInstanceName="dateEdit" EditFormatString="yyyy-MM-dd" DisplayFormatString="yyyy-MM-dd" runat="server" EnableClientSideAPI="true" CssClass="form-control">
<ClientSideEvents Init="FirstDate()" LostFocus="ChangeDate()" />
This code includes two events:
var InitialPay;
var FinalPay;
function FirstDate(s, e) {
var date = s.GetDate();
var dd = date.getDate();
var mm = date.getMonth();
var yy = date.getFullYear();
InitialPay = new Date(yy + ',' + mm + ',' + dd);
}
function ChangeDate() {
var jsDate = dateEdit.GetDate();
var year = jsDate.getFullYear();
var month = jsDate.getMonth();
var day = jsDate.getDate();
FinalPay = new Date(year + ',' + month + ',' + day);
var a = moment([FinalPay]);
var b = moment([InitialPay]);
days = a.diff(b, 'days')
alert(days)
}
The requirement is to capture the initial date before any changes are made and store it in one variable. Then, capture the changed date and save it in another variable. Finally, calculate the difference between these two dates. The current implementation utilizes moment.js
, but other methods can be considered.