You can do it easily with text variables built into InDesign
There may be no need for a script. It depends upon how versatile you need things. Text variables can be limiting in some instances.
A text variable is an item you insert in your document that varies according to the context. For example, the Last Page Number variable displays the page number of the last page of the document. If you add or remove pages, the variable is updated accordingly.
InDesign includes several preset text variables that you can insert in your document. You can edit the format of these variables, or you can create your own. Some variables, such as Running Header and Chapter Number, are especially useful for adding to master pages to ensure consistent formatting and numbering. Other variables, such as Creation Date and File Name, are useful for adding to the slug area for printing.
It's sort of a "basic" InDesign feature and quite broad. A lengthy answer simply detailing the same steps wouldn't really compete with Adobe's own help section on text variables.
I create monthly newsletters for several clients. I use text variables for the months/year. So When I open a file, edit it and save, all the dates update accordingly based upon the month of the edit. That way, a month change isn't overlooked when working on a new iteration.