115

I've looked under insert > ...? but couldn't find anything.

Can this be done via an inbuilt function or a custom script?

5
  • 20
    I'm shocked that Google Docs doesn't already have this feature. It seems like one of the most basic things that modern word processors should have. Commented Mar 12, 2015 at 16:54
  • If you need it for spreadshetts paste =TODAY() in cell. I know question about google-docs. But first in google if google for spreadshets.
    – Fortran
    Commented Nov 20, 2017 at 11:30
  • "=TODAY()" works great
    – Jackssn
    Commented Jun 24, 2018 at 14:42
  • 2
    =TODAY() doesnt work for logging, since it will update to the current date everytime the page is opened. Most times I want to record todays date and not update. If you need to insert todays date for a log file, then you need something else.
    – Hephaestus
    Commented Aug 7, 2019 at 18:43
  • In google docs it's now possible: webapps.stackexchange.com/a/164375/252967 Commented May 4, 2022 at 12:59

6 Answers 6

90

It’s possible to insert todays date through a macro.

Open your Google Document and under Tools select Script editor. This opens Google's script editor where it’s possible to create macros for Google Documents.

Paste this script and save it as Date Macro or something:

/**
 * The onOpen function runs automatically when the Google Docs document is
 * opened. Use it to add custom menus to Google Docs that allow the user to run
 * custom scripts. For more information, please consult the following two
 * resources.
 *
 * Extending Google Docs developer guide:
 *     https://developers.google.com/apps-script/guides/docs
 *
 * Document service reference documentation:
 *     https://developers.google.com/apps-script/reference/document/
 */
function onOpen() {
  // Add a menu with some items, some separators, and a sub-menu.
  DocumentApp.getUi().createMenu('Utilities')
      .addItem('Insert Date', 'insertAtCursor')
      .addToUi();
}
 
/**
 * Inserts the date at the current cursor location in boldface.
 */
function insertAtCursor() {
  var cursor = DocumentApp.getActiveDocument().getCursor();
 
  if (cursor) {
    // Attempt to insert text at the cursor position. If insertion returns null,
    // then the cursor's containing element doesn't allow text insertions.
    var date = (new Date).toLocaleDateString('default', { day: 'numeric', month: 'long', year: 'numeric'}); // use your local (browser) date format with month name
    var element = cursor.insertText(date);
    if (element) {
      element.setBold(true);
    } else {
      DocumentApp.getUi().alert('Cannot insert text at this cursor location.');
    }
  } else {
    DocumentApp.getUi().alert('Cannot find a cursor in the document.');
  }
}

Now refresh or reopen your document and a new menu item appears: Utilities. Under this menu an item appears called Insert Date. Click that to insert todays date at your cursor position.

To change the format of the date you need to change the “format” used in the script. The format can contain the following characters: yyyy-MM-dd'T'HH:mm:ss'Z'

To clarify, this script merely inserts today's date at the cursor location for the day you execute the utility. That's not precisely the same as the =today() function in Google Sheets, which updates the date to the current date whenever you open the spreadsheet. However, this script will save you the trouble of looking up the date and typing it on the day that you execute the script.

11
  • 3
    It defaults to "GMT". If you look at the line containing: Utilities.formatDate(new Date(), "GMT", "yyyy-MM-dd"); it's possible to change GMT to a timezone of choice. Commented Mar 23, 2015 at 14:19
  • 1
    I've made a similar function for SpreadsheetApp (to insert date in active cell). You can find it here: gist.github.com/Eccenux/712ae3d7913e971e46035546b2ccc85b
    – Nux
    Commented Nov 21, 2016 at 11:23
  • 3
    Now.. is there some way to automatically force a script to be inserted into all documents created in an organization?
    – Michael
    Commented Mar 28, 2018 at 18:14
  • 1
    Is there any way to make this script "global" so that for every Google Doc I create or open, the script is there and accessible?
    – Taptronic
    Commented Aug 23, 2019 at 13:41
  • 2
    Just a 2022 update, this is not under Tools -> Script Editor anymore, but under Extensions -> Apps Script.
    – nim.py
    Commented Sep 28, 2022 at 13:40
15

Forget macros. Just link to a cell in Google Sheets!

  1. Go to Google Sheets.
  2. Create a new Google Sheets spreadsheet and name it something like "Today."
  3. In a cell in that spreadsheet, type the following: =TODAY()
  4. Select that cell along with an adjoining cell (which makes it a Table and not just text). Copy the selected cells (using "Edit" --> "Copy" or a keyboard shortcut).
  5. Open a Google Doc or a Google Slideshow and paste the table wherever you'd like for the current day's date to appear.

Voila!

6
  • 4
    Thanks @geekzspot - you mention 'cell' so i presume your talking about a google drive spreadsheet do you know if theres a way to do this in a google drive word document ?
    – sam
    Commented Apr 9, 2014 at 8:36
  • 2
    I'm looking for a more "modified on" date, but if you use Docs to create forms that is pdf'ed or printed, this is the most elegant solution. Commented Jan 22, 2020 at 8:09
  • 1
    This doesn't work in a "Word" document, but it does work in a "Google Docs" document, as described here. The only step missing in this answer is choosing "Link to spreadsheet" after pasting the table. Commented Mar 9, 2020 at 1:26
  • Any better way to do thise these days? I need the current year in a numbered list, so inserting a table throws off the whole paragraph Commented Jan 3, 2023 at 18:58
  • Does this auto-update? Commented Apr 17, 2023 at 9:54
4
  1. Go to Google Sheets and create a new spreadsheet file with a suggestive name such as e.g. Dataset.
  2. Rename the Sheet1 sheet to a more suggestive name such as e.g. Date.
  3. At the cell A1, type =TODAY() and hit Enter, then (with cell A1 still selected) go to Format => Number and select Date, or select More Formats => Custom number format, customize it as you wish (e.g. mmmm dd, yyyy.) and click Apply. Don't forget to change the font type so it matches the font type used in your Google Docs document. E.g. if your document uses the Arial font, then make sure that A1 cell is formatted to use the Arial font, too.
  4. Still with cell A1 selected, select Insert => Chart. By default, a Column chart will be created. Double-click it and, at the Chart editor panel (right side of the screen), go to Setup and change the Chart type to Scorecard chart. Your chart will then become a date field.
  5. Return to your Google Docs document, select the place in the text where you wish to insert such date field, then select Insert => Chart => From Sheets, pick your spreadsheet file at the Files field and click Select, then click onto the Scorecard chart that will show up and hit Import.
  6. Use your (mouse, touchpad, clickpad...) pointer to click and drag one of the chart's (lower-left, upper-left, lower-right or upper-right) corners in order to resize the chart proportionally until its font size matches that of your text.
  7. Double click the chart, then drag the lower side of the rectangle downwards about twice the height of the text (hold the left Alt keyboard key as you do it, so this task is performed in "precise mode"). Click outside of the chart in order to exit the "chart editting mode".
  8. The text of the date chart will still be vertically not aligned with the text of the document. Double click the chart again, then drag the lower side of the rectangle upwards while holding the left Alt keyboard key. Do it until your date text is aligned with the document text.

Footnotes

  • If your date chart doesn't update automatically, press F5 in order to update/refresh your document, then select the date chart and click on the UPDATE button.

  • If the font size of your date chart doesn't match the font size of the text and resizing the chart in the document doesn't work, return to the sheet and change the size of the font there: double click the chart in Google Sheets, then at the Chart editor select Customize, then select Key Value and modify Font size.

2

If you are willing to use a 3rd party program, I use Dash - http://kapeli.com/dash - with a Date and Time snippet. It auto replaces your snippet (mine is 'datetime') with the current date and time. This works system wide.

Dash is only available for OS X and iOS.

4
  • 1
    Dash doesn't look to work with Google Documents. Commented Aug 6, 2015 at 2:34
  • @Rubén - I just checked. It works great. You have to type your shortcut. For example I have @@ for my email. Once you type that Dash replaces it with your text. Commented Aug 11, 2015 at 18:03
  • Google Documents is not listed in the linked page in your answer, by the other hand, looks that Dash is only available for OS X and iOS. Do you know if it's available for other OS? Commented Aug 11, 2015 at 22:01
  • 1
    @Rubén - the list is the programming API docs that come loaded in Dash. Dash works anywhere text entry works. And there are similar auto complete programs available for other OS. Commented Aug 12, 2015 at 21:20
2

Here is my modified version for dating a letter head.

It prints out the current date like '14, August, 2015' in time zone "GMT+2" with font 'Cambria' in size 11.

See following:

function onOpen() {
  // Add a menu with some items, some separators, and a sub-menu.
  DocumentApp.getUi().createMenu('Utilities')
      .addItem('Insert Date', 'insertAtCursor')
      .addToUi();
}

// Inserts the date at the current cursor location.
function insertAtCursor() {

  var cursor = DocumentApp.getActiveDocument().getCursor()


  if (cursor) {
    // Attempt to insert text at the cursor position. If insertion returns null,
    // then the cursor's containing element doesn't allow text insertions.
    var dMy = Utilities.formatDate(new Date(), "GMT+2", "dd, MMMMM, yyyy"); 
    var element = cursor.insertText(dMy);
    if (element) {
     element.setFontSize(11).setFontFamily('Cambria');                       
    } else {
      DocumentApp.getUi().alert('Cannot insert text at this cursor location.');
    }
  } else {
    DocumentApp.getUi().alert('Cannot find a cursor in the document.');
  }
}
1
  • This feature is now available through Insert ->Date
    – Mithil
    Commented Jul 28, 2021 at 0:36
1

Wow! All the above look so complicated. I've just opened a new sheet in Google Drive and used the keyboard shortcut "CTrl+:" and it inserted today's date just like that. Now, if I'm behind on all this, just blame Stack Exchange because it's them who sent me the email with this query in it.

1
  • Cmd-: on Mac. Cmd-Shift-: inserts the time.
    – Evan
    Commented Jul 28, 2023 at 22:48

Not the answer you're looking for? Browse other questions tagged or ask your own question.