javascript Date count validation - Last 3 months -
i populate 2 dates 03-mar-2015
, 03-jun-2015
, if last 3 months option selected.i perform below javascript validation check 90 days. shows validation error 2 dates selected greater 90 days. constraint not allow users select more 3 months duration.
function dttimediff(sender, args) { var startdate = date.parse(document.getelementbyid('ctl00$maincontent$fromyeartxt').value); var enddate = date.parse(document.getelementbyid('ctl00$maincontent$toyeartxt').value); var timediff = enddate - startdate; daysdiff = math.floor(timediff / (1000 * 60 * 60 * 24)); if (daysdiff > 90) { args.isvalid = false; } else { args.isvalid = true; } }
how perform validation 3 months having 91 days(mar,apr,may) , 92 days (jul,aug,sep)? constrain not allow users select more 3 months duration.
you can try calculate month , date separately
function dttimediff(sender, args) { startdate = new date("03-03-2015");/*assume format mm-dd-yyyy*/ enddate = new date("06-01-2015");/*assume format mm-dd-yyyy*/ var timediff = enddate - startdate; startdatemonth = startdate.getmonth() + 1; enddatemonth = enddate.getmonth() + 1; startdatedate = startdate.getdate(); enddateddate = enddate.getdate(); if (enddatemonth - startdatemonth >= 3) { if (enddateddate - startdatedate >= 0) { args.isvalid = true; console.log("in"); } else { args.isvalid = false; console.log("out"); } } }
Comments
Post a Comment