Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert date time in google document

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?

like image 350
rbregt Avatar asked Nov 27 '12 13:11

rbregt


People also ask

Can you insert a date into a Google Doc?

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.

How do I insert time in Google Sheets?

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.


2 Answers

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.

like image 57
Ryan Heitner Avatar answered Oct 06 '22 21:10

Ryan Heitner


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.

Screenshot

like image 35
orschiro Avatar answered Oct 06 '22 20:10

orschiro