Reputation: 529
i am using jquery datepicker.i have to validate that selected date should not be past date from current date like given below
from 2015-06-12 to 2015-05-12
how to validate this ...
Upvotes: 0
Views: 1446
Reputation: 81
Since you're using JS Datepicker, you can restrict the min-date to current date.
Here's a JSFiddle
$(function(){
var d = new Date();
$('#thedate').datepicker({
dateFormat: 'dd-mm-yy',
minDate:"-1d",
maxDate:"d"
});
Upvotes: 0
Reputation: 2922
Just use: Date.parse(date) > Date.now()
for comparison to now,
or Date.parse(comparableDate1) > Date.parse(comparableDate2)
for general comparison
Here's a JSFiddle
Upvotes: 1
Reputation: 21
Here you can find a fiddle example for doing this: http://jsfiddle.net/H3H8s/5/
Script :
if(dateCheck("02/05/2013","02/09/2013","02/07/2013"))
alert("Availed");
else
alert("Not Availed");
function dateCheck(from,to,check) {
var fDate,lDate,cDate;
fDate = Date.parse(from);
lDate = Date.parse(to);
cDate = Date.parse(check);
if((cDate <= lDate && cDate >= fDate)) {
return true;
}
return false;
}
Upvotes: 0