Last active
August 29, 2015 14:04
-
-
Save Lbatson/90316d9cc3124434b595 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var sheet = SpreadsheetApp.getActiveSheet(), | |
rows = sheet.getDataRange(), | |
numRows = rows.getNumRows(), | |
values = rows.getValues(), | |
startTimeCol = 3, | |
endTimeCol = 4, | |
re = ' at'; | |
/** | |
* Retrieves all the rows in the active spreadsheet that contain data and converts Date/Time if necessary | |
*/ | |
function fixDateTime() { | |
for (var i = 0; i < numRows; i++) { | |
var startVal = values[i][startTimeCol], | |
endVal = values[i][endTimeCol]; | |
if (JSON.stringify(startVal).search(re) !== -1) { | |
sheet.getRange(i+1, startTimeCol+1).setValue(JSON.parse(JSON.stringify(startVal).replace(re, ''))); | |
} | |
if (JSON.stringify(endVal).search(re) !== -1) { | |
sheet.getRange(i+1, endTimeCol+1).setValue(JSON.parse(JSON.stringify(endVal).replace(re, ''))); | |
} | |
} | |
}; | |
/** | |
* Adds a custom menu to the active spreadsheet, containing a single menu item | |
* for invoking the fixDateTime() function specified above. | |
* The onOpen() function, when defined, is automatically invoked whenever the | |
* spreadsheet is opened. | |
* For more information on using the Spreadsheet API, see | |
* https://developers.google.com/apps-script/service_spreadsheet | |
*/ | |
function onOpen() { | |
fixDateTime(); | |
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); | |
var entries = [{ | |
name : "Fix Date/Time", | |
functionName : "fixDateTime" | |
}]; | |
spreadsheet.addMenu("Script Center Menu", entries); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment