Please i need your assistance on how to differentiate between two dates like (Start Date) 22/04/2017 - 24/04/2018 (End Date) with a result as 12months 2days. Should be done in client side. Any help pls
Asked
Active
Viewed 75 times
-1
-
Similar question is already asked. you can check it for answers. https://stackoverflow.com/questions/542938/how-do-i-get-the-number-of-days-between-two-dates-in-javascript – Karan Jun 23 '18 at 07:19
3 Answers
0
Try this Code to solve your problem.
var date1 = new Date("22/04/2017");
var date2 = new Date("24/04/2018");
var timeDiff = Math.abs(date2.getTime() - date1.getTime());
var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));
alert(diffDays);

ravi polara
- 564
- 3
- 14
0
var dateDiffInDays = function(startDate, endDate) {
var timeDiff = Date.parse(endDate) - Date.parse(startDate);
return daysDiff = Math.floor(timeDiff / (1000 * 60 * 60 * 24));
}
console.log(dateDiffInDays("2018-05-01", "2018-06-23"));

Snezhana
- 31
- 1
0
You can do the following:
var startDate = moment("22/04/2017", "DD/MM/YYYY");
var endDate = moment("24/04/2018", "DD/MM/YYYY");
var months = endDate.diff(startDate, 'months');
var days = endDate.subtract(months, 'months');
var diff = months + ' months ' + days.diff(startDate, 'days') + ' days';
$('#result').html(diff);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.12.0/moment.js"></script>
<div id="result"></div>

Mamun
- 66,969
- 9
- 47
- 59