Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

884
Views
Disable past date in FullCalendar for dateClick

Those who still looking for a solution on how to disable past date click on Dateclick event on FullCalendar. can try see solution below, if any of the reader had other idea can post other solution below. It would be much better if there is another easy way. The more solution, the better it would be.

about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

It's possible to improve on your string-manipulation of dates, by doing a simple comparison as follows:

dateClick: function (info) {
  var clickedDate = getDateWithoutTime(info.date);
  var nowDate = getDateWithoutTime(new Date())
  if (clickedDate >= nowDate) alert("Future date");
  else alert("Past date");
}

It is helped by this function:

//get date without the time of day
function getDateWithoutTime(dt)
{
  dt.setHours(0,0,0,0);
  return dt;
}

Demo: https://codepen.io/ADyson82/pen/ZErwJGx


One other option to achieve the same goal is to use the validRange functionality. This lets you dynamically set a start date, before which all dates are disabled:

validRange: function (nowDate) {
  return {
    start: nowDate
  };
},

Demo: https://codepen.io/ADyson82/pen/VwQgWJO

The slight downside of this though is that it also hides any events which occur before the current date - you may not want this.


Therefore, another alternative is to use selectAllow to restrict where the user can select. Note that this relies on you using the select callback rather than dateClick - but that should not be a big problem.

selectAllow: function (info) {
  return (info.start >= getDateWithoutTime(new Date()));
}

Demo: https://codepen.io/ADyson82/pen/VwQgzZJ

about 4 years ago · Santiago Gelvez Report

0

Below is just my current solution to disable past date on FullCalendar. Any idea or improvement would be appreciate to improve the code below.

dateClick: function(e) {

    // Get Today
    var dt = calendar.getDate();
    var year = dt.getFullYear();
    var month = dt.getMonth() + 1;
    var day = dt.getDate();

    if(month < 9){
        month = '0'+month;
    }

    if(day < 9){    
        day = '0'+day;
    }
    
    var today = year + '-' + month + '-' + day;

    // Get Selected Date
    var check = e.dateStr;
                
    let A = today.toString();
    let B = check.toString();

    alert('Date A: ' + A );
    alert('Date B: ' + B );

    if(B >= A){
        alert('Past Date');
    }

    else{
        alert('Future Date');
    }
},
about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!