I would like to define a custom function in Google Sheet. This function should do something very simple, yet I have not managed to find how to do it. I am very confused with all the answers I read because I can't find a clear reference about dealing with dates in google scripts.
From what I understand, basic date manipulations can be done with:
new Date()
: from what I understand, it defines a object which has some properties. I don't know how to use the date of a cell and convert it as such an object.Utilities.formatDate()
: this is to change the format of the date seen as a string.- the library
Moment
(http://momentjs.com/)
In the end, how can I input two dates (e.g. 31/01/2016
) and, say, find the maximum between the two and extract the month of the first one?
function myfun(date1,date2) {
// month = month of date 1
// return maximum(date1,date2);
}
I am also interested if someone can explain the outlines of dealing with dates, or indicate a good reference.