Forked from defHLT/Insert current date in Google Spreadsheets
Last active
March 17, 2022 13:27
-
-
Save chrisbennell/65f9fb82f677c3a5c436c9535b268dbd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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