-1

Need differentiation of 2 Date objects..

Need to calculate cost based on total days of working or Total hours of working betn the date1 and date2

also need to calcualate Number of holidays within the period of time !

$(document).ready(function () { 
    $('#CostMaster_labour_deallocationdate').change(function(){
        var date1 = $('#CostMaster_labour_deallocationdate1').val();
        var date2 = $('#CostMaster_labour_deallocationdate').val();
    });
});
user3378215
  • 117
  • 1
  • 2
  • 9

3 Answers3

3

Take a look at momentjs -

var a = moment([2007, 0, 29]); // you can pass date object
var b = moment([2007, 0, 28]);
a.diff(b, 'days') // 1

Docs --> http://momentjs.com/docs/#/displaying/difference/

Adil Shaikh
  • 44,509
  • 17
  • 89
  • 111
1

Use following Javascript Function::

 function CheckDateDifference() {
        var date1 = $('#CostMaster_labour_deallocationdate1').val();
        var date2 = $('#CostMaster_labour_deallocationdate').val();
        var diff = Math.round((date1 - date2 ) / 1000 / 60 / 60 / 24);
        return diff;
    };
Rahul
  • 2,309
  • 6
  • 33
  • 60
0

1.Try using datejs framework to easily do all your date time calculations.

2.Else try this

function DateDiff(var /*Date*/ date1, var /*Date*/ date2) {
    return date1.getTime() - date2.getTime();
}

This will return the number of milliseconds difference between the two dates. Converting it to seconds, minutes, hours etc. shouldn't be too difficult.

Abinaya Selvaraju
  • 1,212
  • 1
  • 10
  • 16