jquery - How to take today's date and onward only not previous date? -
i want insert today's date , onward not previous date insert data base takes date tomorrow , onwards not today's
var = moment(new date()); var mdate = moment(new date($('.meetingdate').val())).format("m/d/yyyy"); //now.format("yyyy/mm/dd"); var duration = moment.duration(now.diff(mdate)); var days = duration.asdays(); //alert(now + mdate); alert(days); if (days > 0) { e.preventdefault(); alert("please enter valid date"); $validation = false; }
it because when calculate, completes day, , takes next day in account. so, if more 12:00:00 am, need calculate using previous day. so, is:
var mydate = new date(); if (mydate.gethours() != 0 && mydate.getminutes() != 0 && mydate.getseconds() != 0 && mydate.getmilliseconds() != 0) mydate.setdate(mydate.getdate() - 1); var = moment(mydate); var mdate = moment(new date($('.meetingdate').val())).format("m/d/yyyy"); //now.format("yyyy/mm/dd"); var duration = moment.duration(now.diff(mdate)); var days = duration.asdays(); //alert(now + mdate); alert(days); if (days > 0) { e.preventdefault(); alert("please enter valid date"); $validation = false; }
this should work out.
or in cleaner way, can set new date's time 0:00:00:0000
.
var mydate = new date(); mydate.sethours(0) mydate.setminutes(0) mydate.setseconds(0) mydate.setmilliseconds(0)
Comments
Post a Comment