I would like to insert a timestamp (date and/or time) into Google Documents. The support documentation () says that there should be a keyboard shortcut, but it does not work in my environment (Win7 + IE9).
Can anyone provide me with a Google Apps script to achieve this?
Unfortunately, there isn't a quick way to insert the date into a Google document. You'll need to use the document's Script Editor for this. Luckily, there are a number of pre-created codes online that you can insert into the Script Editor to make "Insert Date" pop up on the page's settings.
Inserting Static Times or Dates into Google Sheets You'll have to use a keyboard shortcut instead. To insert the current date, click on your empty cell, and then click the Ctrl+; (semi-colon) keys on your keyboard. To insert the current time, click Ctrl+Shift+: (colon) on your keyboard instead.
This works well
In Google Docs : Tools -> Open Script Editor and save this script
function onOpen() { var ui = DocumentApp.getUi(); // Or FormApp or SpreadsheetApp. ui.createMenu('Custom Menu') .addItem('Insert Date', 'insertDate') .addToUi(); } function insertDate() { 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 d = new Date(); var dd = d.getDate(); dd = pad(dd, 2) var mm = d.getMonth() + 1; //Months are zero based mm = pad(mm, 2) var yyyy = d.getFullYear(); var date = dd + "-" + mm + "-" + yyyy; 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.'); } } function pad (str, max) { str = str.toString(); return str.length < max ? pad("0" + str, max) : str; }
Reload the Doc, Accept the permissions.
I am not sure if an add-on falls under the category Google Apps Script you were asking for, bug Text Factory provides the feature to insert a time-stamp.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With