How to put in a Cell the number of days pass from a specific date. For example:
Column1: 12/05/2013 18:00:00 Actual Days using Function New Date() Column2: The script will insert the numbers of days (Today - Column1) = 4
The script should be insert in the column 2 the number of days pass from today. Today is 16/05/2013 23:00, the script will insert 4. If possible due this?
I'll appreciate if you can help me.
That function was passed by friend but I think doesn't work because the date is not in milliseconds but the result in the cell should be number of days
}
function formatting2(event) {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); // get the sheet
var columnF = sheet.getRange(2, 1, sheet.getLastRow()-1, 1);
var updateage = sheet.getRange(2, 2, sheet.getLastRow()-1, 1);
var fValues = columnF.getValues(); // get the values
var result = new Date();
updateage.setValue(result-fValues)
}
This is a possible way to get the result you want, I wrote it as a custom function, ie you have to put it in the the cell where you want it to appear in the form
=dayToToday()
here is the script with a few logs and comments to show intermediate values.
EDIT : if I understand your use case I suggest you abandon the custom function aproach (that I never use since I don't like it so much) and go for this solution that uses a timer trigger and/or a menu to update values in your spreadsheet in one batch.
(ps : sorry for not having answer quickly enough... too busy these days :-)
second EDIT:
when using
var data = sh.getRange(1,1,sh.getLastRow(),2).getValues();
the numbers in getRange are start row, start column, number of Rows, number of Columns so you'll have to gat a range that includes the columns you want and then use data [n][columnNumber-1] to get the corresponding value. (-1 because array start from 0 and columns count from 1 (A in fact but A is first column ;-)) if you need a variable reference then let me know because the function must be modified to accept 2 variables (a ref and another one).
LAST EDIT (I hope)
I changed some details... see [9] and [5] index corresponding to J and F
update/edit
result in hours (following request in comments)