Compare Todays Date With Calender Date (for Next Seven Days Only Else Generate Alert )
I have to compare todays date with calender date(picking date using date picker ajax). If date difference is more than 7 days then generate alert. var mydate = new Date();/
Solution 1:
var mydate = new Date(); //Todays date
txtDate.value='16-Jul-2012'; //date picker date in this format
var newDate = new Date(txtDate.value); //make date object
var difference = Math.ceil((newDate-mydate) / (60*60*24*1000)); //calculate days
if (difference > 7) alert('more than 7 days');
Solution 2:
var datePicked = '26-Jun-2012';
var datems = Date.parse(datePicked.replace(/-/g, " "));
var dateNow = new Date();
dateNow.setHours(0,0,0,0);
var msDiff = Math.abs(Number(dateNow) - datems);
// 7 Days = 604 800 000 ms
if(msDiff > 604800000) alert("Time difference greater 7 days");
Post a Comment for "Compare Todays Date With Calender Date (for Next Seven Days Only Else Generate Alert )"