Calculating years betwen two dates (one from datepicker)
Hi everyone,
I have some problem with calculating "exactly" number of years between two dates (one from string and second from datepicker). I write the code who calculating tstamp from datepicker, but I can't figured out how to write the code who will calculating tstamp from "text" who has right syntax (dd/mm/yy).
here is my code:
- <form action="#" method="post">
<div id="end_date">20/11/2012</div>
<label for="birthday">to
<input type="text" name="birthday" id="birthday" />
</label>
<label>tstamp1
<input type="text" name="total_hour1" id="total_hour1" />
</label>
<label>tstamp2
<input type="text" name="total_hour2" id="total_hour2" />
</label>
</form>
And my js:
- $(function() {
$( "#birthday" ).datepicker({ dateFormat: 'mm/dd/yy' });
});
$('#birthday').change(function() {
var g = $('#end_date').val();
var h = $('#birthday').val();
date1= g.split("/");
var timestamp = (new Date(date1[2],date1[1] - 1,date1[0]));
$('#total_hour1').val(timestamp);
date2= h.split("/");
var timestamp = (new Date(date2[2],date2[1] - 1,date2[0]));
$('#total_hour2').val(timestamp);
});
I will be glad for any help.