- Open the Tools menu and choose Script Editor
- Copy and paste the following text:
- Click the save button to save your script, then reload your document for the changes to take effect.
- Select the row or the cell in your spreadsheet where you want to add your data. From the Format menu, choose Number and then choose Date/Time. If you omit this step, it will only show the date without the time.
- Now select the cell where you want to add the current date. In the menu bar, look for a menu on the right that says AddDateTime. Click Add date and time to add the current date and time.
function onOpen() {
var spreadsheet = SpreadsheetApp.getActive();
var menuItems = [
{name: 'Add date and time', functionName: 'addDateTime'}
];
spreadsheet.addMenu('AddDateTime', menuItems);
}
function addDateTime() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var cell = ss.getActiveCell().setValue(new Date());
}