find difference between two dates in angularjs

Introduction:

AngularJS is one of the greatest frameworks which a web developer must need to learn. It has many advantages. It is very easy to learn because there are lots of tutorials available on the internet. Today I am going to share a tutorial with you guys. This tutorial will help you to find "Difference Between Two Dates". I am writing this tutorial here because many of my friends asked for this on my Facebook Page.

Steps to Get Difference Between Two Dates: 

Here I am going to share the code which shows day count of a specified date to current date. For this, We have to create a javascript code which provides the current date. The code which I shared will help to get it. 
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();
if(dd<10) {
dd='0'+dd
}
if(mm<10) {
mm='0'+mm
}
today = yyyy+'/'+mm+'/'+dd;
Now we need to input two dates. The above code will give us the current date and we need to put another date. The code to get the difference between two dates are given below.
var date2 = new Date(today);
var date1 = new Date(date);
var timeDiff = Math.abs(date2.getTime() - date1.getTime());
$scope.dayDifference = Math.ceil(timeDiff / (1000 * 3600 * 24));
return $scope.dayDifference;
On the above code, The date1 and date2 are representing the date. and it will compare by $scope.dayDifference. Then finally, it will return the result by using the return $scope.dayDifference.

An output of The Above Code:

You can use the script for many of your AngularJS Applications. I used this code for my Asset Tagging Web Applications and for my Warranty Web Application.

Interesting Article for Web Masters:

I hope you well enjoyed this article. If you have any doubts that related to this article. Please let me know by using my FB page or by using the comment box that given below. Thanks
Next
This is the most recent post.
Previous
Older Post

0 comments:

Post a Comment

Wapmaster or Webmaster can Comment Us with the following Comment Box . Don't add Links to your site for Spamming our Blog .. Once you add Comment with Link . It will be deleted immediatly by our Admins .

 
Top