Welcome to my Blog

I am Nelson Desai. I complete computer engineering.

This is my personal blog. Here I share some post, which can helpful for me, my friends and you.

Some post may be illegal to share like some crack and keys. but, i think.. which things put online then it's not be secure any more whatever company try.

So, I requested you pls download and use it at your risk. and don't upload it again online.

Thank You for peeping my blog.. Have a Good Day!

Showing posts with label Date Difference. Show all posts
Showing posts with label Date Difference. Show all posts

Calculating the difference between two dates in JavaScript




Hi guys, 
Some day ago i want a difference between two dates to check it's greater or less then..
After searching i got many solutions but best and easy solution it's here...

var dp_b_d = document.getElementById('dp_birth_date').value; 
// Get like 12/04/1990 date format  // Or if u have different format then u should convert it or get it by this link Click Here
var dp_d_d = document.getElementById('dp_death_date').value;
// Get like 15/04/1990 date format

var myDateArray = dp_d_d.split("/");  
var myDateArray2 = dp_b_d.split("/");

// Split it by using "/"  if your date format '15.04.1990' then split with '.'[dot] 

var EndDate = new Date(myDateArray[2],myDateArray[1],myDateArray[0]);
// Always pass this type value in Date(YEAR, MONTH, DATE)  


var Today = new Date(myDateArray2[2],myDateArray2[1],myDateArray2[0]);

var ONE_DAY = 1000 * 60 * 60 * 24;

var date1_ms = EndDate.getTime();
var date2_ms = Today.getTime();
// Convert both dates to milliseconds
 
var difference_ms = date1_ms - date2_ms;

var total_days =  difference_ms/ONE_DAY;
// Get difference in total days.

return total_days; 
// Here it's return 3days in this example.


--
Thank You
Nelson Desai

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by NDR Group | Bloggerized by Er. Nelson Desai | Love U My Friends