javascript – How to establish an expiration date of access to a file from a period established in days?

Google Apps Script is based on JavaScript which has the Date data type for the dates.

You can set today's date using new Date () or using new Date (year, month, day) where year, month and day are integers, being month a base index 0, that is, the month of January is 0, February is 1, March 2 and so on.

To determine a validity date as of today, knowing the year, the month index and the day, it is only necessary to add the date in days number today.

To know the year, index of month and day of today, we can use the following methods:

  • getFullYear () returns the year, for example 2019
  • getMonth (), returns the index of the month, for example 2 for the month of March.
  • getDate (), returns the number of the day of the month, for example 23.

For simplicity, an example using JavaScript is included

(function () {
var answer = prompt ('Term in days'); // Even if we write a number, the answer is passed as a string (String)

// Start part supported by Google Apps Script

var hoy = new Date ();
var Date_Adventure = new Date (
today.getFullYear (),
today.getMonth (),
today.getDate () + parseInt (answer) // parseInt converts a string to a whole number

// End part supported by Google Apps Script

alert ('The expiration date is' + Date_Quality);

}) ()