I’m comparing two dates and my code goes like this.
jQuery('.newAppointment a.ui-state-default').click(function() {
var date = jQuery(this).parent().attr('title');
var d = jQuery.datepicker.parseDate('dd/mm/yy',date.toString());
alert(d);
var today = new Date;
var t = jQuery.datepicker.parseDate('dd/mm/yy',today.toString() );
alert(t)
if(t > d){
url = "/users/" + user_id + "/events/new?type=Surgery"+"&day=" + escape(date);;
window.location = url;
}else{
alert("you cannot add appointment to past dates");
}
});
but am getting error in firebug.
uncaught exception: Missing number at position 0
can anyone tell me where I’m doing wrong.
From the fine manual:
So your error is coming from jQuery-UI. The format you get from
date.toString()depends on the browser and the locale, there’s no reason to expect it always bedd/mm/yyand in your case, it isn’t.Your
dateis already a string and in a known format (presumablydd/mm/yy) so you should be able to do this:to get a Date. Then you can get
todaywith just:and compare them directly:
If you want to throw away the hours, minutes, and seconds then: