chopz
chopz

Reputation: 381

Google Apps Script - Validating Dates in Form

It seems to me that GAS has no feature to do validation besides 'required' in Google Forms.

I have 2 dates. Start Date & End Date. I'm figuring if there's any way to check and make sure end date is not earlier than start date.

It seems like using UI or HTML form is the way to go. But I just want to see if anyone has other alternatives?

If the answer is no, then I'll probably use this method > Form Validation Before Submission

Upvotes: 0

Views: 4201

Answers (1)

rpm
rpm

Reputation: 583

I don't know if you want to check in following manner or not. But, as you said you have two dates, you can validate with following function.

function validateDates (startDate, endDate) {

    var diffInMilliSecs = (endDate.getTime() - startDate.getTime());
    var diffInDays = diffInMilliSecs/1000/60/60/24;
    var diffInDays = Math.round(diffInDays);


  Logger.log('Difference between start date and end date : ' + diffInDays);
    if(Math.abs(diffInDays < -1))
      Logger.log('End date is older than start date');
}

Upvotes: 1

Related Questions