Is it possible to add (insert) a variable for the current date into a Google Docs that would automatically update each time I open the document?
Some criteria:
-
The date position should be variable, i.e. allowing me to insert the date a different positions of a page/paragraph
-
The document should still be shareable, i.e. people opening my document will also be displayed with the current date
Best Answer
Short answer
At this time, variables is not a built-in feature of Google Docs and Google Apps Script, the platform to extend Google Docs, does not include a class or method to handle them.
Alternatives
Alternative 1
One alternative is use a text pattern but you should be sure that it will match only the date that you want to update.
Alternative 2
Another alternative is to use the class NamedRange but bear in mind that
Code:
The following code, intended to be used in a script bound to a Google Document, has two main functions:
For debugging purposes are being used
"Known-issues": The update function replaces the whole paragraph.
To test the code, copy it, then go to your Google Docs, create a new document, click on Tools > Script Editor, select Blank Project, paste the code, save the project, assign a name, run on time to authorize the app, close your doc and open again. A new menu called "Utilities" will be displayed. From there you can call the main functions.
Below there are some items of different kind (questions, specifications, etc.) that could serve to get inspiration or point to the "right direction" to find a "solution"
Footnotes