This particular code snippet is taken from a.jsp:
<script type="text/javascript" >
function checkDates(date1, date2)
{
var x = date1.split('/')
var y = date2.split('/')
var firstDate = new Date(x[2],x[0],x[1])
var secondDate = new Date(y[2],y[0],y[1])
var difference = (secondDate - firstDate )
var daysDifference= difference / (1000 * 60 * 60 * 24);
}
</script>
<% String initialDate="2013/07/12";
String endDate="2013/07/14";%>
<script>
var result=checkDates('$initialDate','$endDate');
</script>
<body>
<% String scriptCode="<script>document.writeln(result)</script>";
out.println("Output value="+scriptCode); %>
</body>
The objective here is to extract the number of days (as 'daysDifference') between two given dates ('initialDate' and 'endDate') as an output. However, instead of getting the desired calculation, the current output appears as "Output value=NaN". Can anyone assist in identifying the issue with this coding? Appreciate any help.