Is form input date before today - Node.js HTML

Node.js examples for HTML:Form

Description

Is form input date before today

Demo Code


function isBeforeToday(inputStr) {
  if(inputStr == null || inputStr == '') return false;
  var myDate_array=inputStr.split("/");
  var yr1 = myDate_array[0];
  var m1 = myDate_array[1]-1;
  var d1 = myDate_array[2];
  
  var today = new Date();
  var yr2 = today.getFullYear();
  var m2 = today.getMonth();
  var d2 = today.getDate();

  if (yr1 > yr2) return false;
  if (yr1 < yr2) return true;
  
  if(m1 > m2) return false;
  if(m1 < m2) return true;   

  return d1 < d2;
}

Related Tutorials