I can't seem to get the below code to work properly. While it calculates the difference in the dates, it doesnt account for the years, which throws it way off. The below code returns a difference of only 4 days and ignores the years?
How can this be fixed?
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function test() {
var today = "27/11/2013"
today = new Date(today.split('/')[2],today.split('/')[1],today.split('/')[0]);
var date2 = "23/02/2011"
date2 = new Date(date2.split('/')[2],date2.split('/')[1],date2.split('/')[0]);
var diff = today.getDate() - date2.getDate()
alert(diff)
}
</script>
</head>
<body>
<input type="button" value="test date" onclick="test()"/>
</body>
</html>