Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save chrisbennell/65f9fb82f677c3a5c436c9535b268dbd to your computer and use it in GitHub Desktop.
Save chrisbennell/65f9fb82f677c3a5c436c9535b268dbd to your computer and use it in GitHub Desktop.
// Insert current date in Google Spreadsheet
function onOpen() {
var ui = SpreadsheetApp.getUi();
// Or FormApp or SpreadsheetApp.
ui.createMenu('Date')
.addItem('Insert Date', 'insertDate')
.addToUi();
}
function insertDate() {
var cell = SpreadsheetApp.getActive().getActiveCell();
if (cell) {
var element = cell.setValue(Utilities.formatDate(new Date(), 'GMT', 'dd/MM/yyyy'));
// For formatting codes see: http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
} else {
SpreadsheetApp.getUi().alert('Cannot get active cell.');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment