How to subtract two angularjs date variables

后端 未结 7 1104
说谎
说谎 2020-12-01 21:53

I am fairly new to angularjs, but here it goes. I am able two dates through angularjs in the form dd/mm/yyyy, but what I need to do is somehow subtract the two

7条回答
  •  情书的邮戳
    2020-12-01 22:30

    I tried the below one and it worked out for me

    var selecteddate = new Date($rootscope.selectvalue);
    $scope.firstDate = selecteddate .getTime();
    $scope.SecondDate = new Date().getTime();
    

    selected date is the one which is selected from calender and it is coming from parent scope. second date will be today's date. later i will find difference using moment diff.

    var differenceinDays=parseInt(
          moment.duration(
            moment($scope.firstDate).diff(
              moment($scope.SecondDate)
            )
          ).asDays()
        );
    

    I am using parseInt because i want to return the integer value only

    Hope this works

提交回复
热议问题