In this article you will learn how to calculate the number of days between two different date range in javascript.
<script language="javascript" type="text/javascript">
var start_date = "2009-10-01".split("-");
var end_date = "2009-10-06".split("-");
var date1 = new Date(start_date[0], start_date[1]-1, start_date[2]);
var date2 = new Date(end_date[0], end_date[1]-1, end_date[2]);
var ONE_DAY = (1000 * 60 * 60 * 24); // The number of milliseconds in one day
// Convert both dates to milliseconds
var date1_ms = date1.getTime();
var date2_ms = date2.getTime();
var difference_ms = Math.abs(date1_ms - date2_ms); // Calculate the difference in milliseconds
var date_diff = Math.round(difference_ms/ONE_DAY)+1; // Convert back to days and return
alert (date_diff);
</script>
1 comment:
Good Job ...............Carry on
Post a Comment