Last active
September 6, 2017 15:00
-
-
Save jsdbroughton/1f9b7039525c0bc60974b7efdfd67bb2 to your computer and use it in GitHub Desktop.
This was prepared to help with a question posted on the Google Apps Script G+ forum. https://plus.google.com/110871587349095016187/posts/NTH6kg94QUr
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
function findDateCellWithinADataRow() { | |
// Assumes an embedded script. | |
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); | |
// Pretend this is the way you want to get teh data | |
// perhaps from the Google Form submission event. | |
var row = ss.getRange(rowId, 1, 1, ss.getLastColumn()); | |
var rowValues = row.getValues()[0]; | |
// Pretend we are sure the date value always looks like this dd-mm-yyyy | |
var datePattern = /(\d{1,2})-(\d{1,2})-(\d{4})/; | |
// Pretend we only need to get the date value from the first cell that matches | |
var dateCells = rowValues | |
.filter(function(cell){ | |
return cell.match(datePattern); | |
}).map(function(dateCell) { | |
return (new Date(dateCell | |
.match(datePattern) | |
.slice(1) | |
.reverse() | |
.join('/'))); | |
}); | |
var firstDateCell = dateCells[0]; | |
debugger; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment