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
0 comments:
Post a Comment