Reputation: 73
I have two date Picker one is for FromDate and another is for ToDate and i want to subtract both date so that i can get DateDiffrence
using j Query I understand i can not store two Selected date in variable and then i can perform Subtraction.
<script>
function deFromDateChanged(s, e) {
var deFromDate = (s.GetInputElement().value)
alert(deFromDate );
}
function deToDateChanged(s, e) {
var deToDate = (s.GetInputElement().value)
alert(deToDate );
}
var ResultDate = deToDate - deFromDate //That is Wrong I can Not access
</script>
DateEdit
<td>Issues Date:</td>
<td>
<dx:ASPxDateEdit ID="deFromDate" runat="server" Width="220px" AllowUserInput="False" Height="25px" EditFormatString="dd-MMM-yyyy" DisplayFormatString="dd-MMM-yyyy" EditFormat="Custom"
Theme="Office2003Blue" ClientInstanceName="deFromDate" OnInit="deFromDate_Init">
<DropDownButton Image-Url="../Images/calendar.png" Image-Height="23px" Image-Width="23px"></DropDownButton>
<ClientSideEvents DateChanged="deFromDateChanged" />
</dx:ASPxDateEdit>
</td>
<td>
<dx:ASPxDateEdit ID="deToDate" runat="server" Width="220px" AllowUserInput="False" Height="25px"
EditFormatString="dd-MMM-yyyy" DisplayFormatString="dd-MMM-yyyy" EditFormat="Custom"
Theme="Office2003Blue" ClientInstanceName="deQuoDate" OnInit="deToDate_Init">
<DropDownButton Image-Url="../Images/calendar.png" Image-Height="23px" Image-Width="23px"></DropDownButton>
<ClientSideEvents DateChanged="deToDateChanged" />
</dx:ASPxDateEdit>
</td>
As i can understand i cn not access both Date value in one function is there any alternate way to do same
Upvotes: 0
Views: 41
Reputation: 267
Your deFromDate and deToDate variables are stored locally in your functions.
To use the variables outside the function you have to inizialize them outside:
var deToDate;
var deToDate;
Then assign the value inside the functions
function deFromDateChanged(s, e) {
deFromDate = (s.GetInputElement().value)
alert(deFromDate );
}
function deToDateChanged(s, e) {
deToDate = (s.GetInputElement().value)
alert(deToDate );
}
and then subtract two date object
var ResultDate = Math.abs(deToDate - deFromDate); //difference in milliseconds
Upvotes: 2