Skip to content Skip to sidebar Skip to footer

How To Fix This "TypeError: Cannot Find Function GetTime In Object"?

I'm using this function in a Google Apps Script: function dateDiffYears() { var datas = [ [Date(2005, 7, 20), Date(2004, 2, 17)], [Date(2008, 9, 1),Date(2007, 5, 25

Solution 1:

I don't understand this error because clearly Sun Jan 26 2014 10:23:10 GMT-0200 (BRST) is a date object.

Clearly it isn't a Date object. Perhaps it's a string, or some Google Apps Script object that gets output a bit like a date but doesn't have a getTime function. Perhaps it's a Range object containing a date.

If it were a Date object, it would have the getTime method.

How to fix it?

Without knowing how you get d1 and d2, it's impossible to say. If it's a Range object, for instance, perhaps you can get the date via getValue.

The first step is to figure out what the object actually is. Perhaps setting a breakpoint on the first line of dataDiff and inspecting the arguments.


Solution 2:

In your code:

function dateDiffYears() {
  var datas = [ [Date(2005, 7, 20), Date(2004, 2, 17)],
              [Date(2008, 9, 1),Date(2007, 5, 25)], 
              [Date(2010, 11, 2),Date(2010, 7, 28)], 
              [Date(2014, 0, 24),Date(2013, 1, 27)] ];

creates arrays of strings representing the current date and time, it doesn't create Date objects. Further, all arguments are ignored. Date(andything in here) is equivalent to:

(new Date()).toString();

per ECMA-262:

All of the arguments are optional; any arguments supplied are accepted but are completely ignored. A String is created and returned as if by the expression (new Date()).toString()…


Post a Comment for "How To Fix This "TypeError: Cannot Find Function GetTime In Object"?"