Comparing two dates in javascript

From Fabrik

Jump to: navigation, search

you will first need to update from the SVN as I've added in some new event handling to deal with calling fabrik js events when the calendar itself closes:

now edit your end date element add a new blur event with the following code:

var startid= 'jos_events___start_date';
 
var endid = 'jos_events___end_date';
 
var start = $(startid).getValue().split('-');
 
var end = $(endid).getValue().split('-');
 
if(start.length > 1){
 
var startdate = new Date();
startdate.setFullYear(start[0]);
startdate.setMonth(start[1].toInt() - 1);
startdate.setDate(start[2]);
var enddate = new Date();
enddate.setFullYear(end[0]);
enddate.setMonth(end[1].toInt() - 1);
enddate.setDate(end[2]);
if(enddate < startdate){
  alert('woops your end date is earlier than your start date');
  $(endid).value = ;
}
 
}

edit it so that the first two lines point to the id's of your start and end date fields, this also presumes that your date elements are recording the dates in the format 'yyy-mm-dd';

Personal tools