Dates in Frevvo

Automatically Pull Current Date

date_ctrl.value = frevvo.currentDate();
//Setup a Trigger to initalize the rule
if (form.load) {
    //Date control is named Date
    Date.value = frevvo.currentDate();
}
Invalid if Before Today
// frevvo currentDate method gets today in users timezone
var today = frevvo.currentDate().split('-');
var today_date = new Date(today[0], today[1]-1, today[2]);
var bd = DOB.value.split('-');
var bd_date = new Date(bd[0],bd[1]-1,bd[2]);
 
if (bd_date > today_date) {
 
    // needs a Message control named MyMsg
    MyMsg.value = 'Birth Date must be earlier than today!!!!'
    DOB.valid = false;
} else {
    MyMsg.value = 'This is a good Birth Date: ' + DOB.value;
    DOB.valid = true;
}
When you have a scenario when the date control is in a repeater:
var today = frevvo.currentDate().split('-');
var today_date = new Date(today[0], today[1] - 1, today[2]);
for(var i=0; i<Date_CTRL_Name.value.length; i++){
  var approve = Date_CTRL_Name[i].value.split('-');
  var approve_date = new Date(approve[0], approve[1] - 1, approve[2]);
  if (approve_date > today_date) {
    Date_CTRL_Name[i].valid = false;
  } else {
    Date_CTRL_Name[i].valid = true;
  }
}
if(Repeater_Name.itemAdded){var x;}
Calculating specific number of days/months/years from specific date:

var someDate = {CONTROL_DATE}.value;
var today = frevvo.currentDate();
var past = frevvo.addToDate(today, 'y', '-100'); //Calculates 100 years before today (if the current date is 04/12/2000, it gives 04/12/1900)
var future = frevvo.addToDate(someDate, 'm', '3'); //Calculates 3 months from someDate (if the date is a birthday on 04/12/2000, it gives 07/12/2000)
var tomorrow = frevvo.addToDate(today, 'd', '1'); //Calculates tomorrow from today (if the current date is 04/12/2000, it gives 04/13/2000)
// Setting the {CONTROL_DATE} to false if it is not in the past
// Also prints a message to user asking them to enter a valid date before today
if ( someDate >= today ) {
  
  {CONTROL_DATE}.valid = false;
  {CONTROL_DATE}.status = "Please enter a valid date before today's date.";
  
} else {
  
  {CONTROL_DATE}.valid = true;
  {CONTROL_DATE}.status = null;
  
}
 Simple “Years in Past” calculations
if( YEAR.value.length > 0 ) {
  
  var today = new Date();
  var y = today.getFullYear();
  var yearsBack = 5; //Number of years in the past to allow
  
  if( y - yearsBack <= YEAR.value && YEAR.value <= y ) {
    YEAR.valid=true;
  } else {
    YEAR.valid=false;
    YEAR.status="Please specify a year from " + y - yearsBack + " to " + y;
  }
}
Date Dropdown Control: Range of 10 Years from Current Year:
if(form.load) {
  var today = new Date();
  var year = today.getFullYear();
  var month = today.getMonth();
  var rangeOfYears = 10;
  var first = year -(rangeOfYears / 2);
  var years = [];
  for (var i=0; i < rangeOfYears; i++) {
    years[i] = (first + i).toString();
  }
  Year.options = years;
}
Date Dropdown Academic/Fiscal Years
if (form.load) {
  
  var today = new Date();
  var year = today.getFullYear();
  var month = today.getMonth();
  
  var rangeOfYears = 4;
  
  var first = year -(rangeOfYears / 2);
  var years = [];
  
  for (var i=0; i < rangeOfYears; i++) {
    
    years[i] = first + "-" + ( first + 1 );
    first ++;
    
  }
  
  FiscalYear.options = years;
  
  if (month < 7) {
    
    FiscalYear.value = (year - 1) + "-" + (year);
    
  } else {
    
    FiscalYear.value = year + "-" + (year + 1);
    
  }
  
}