Solve - date.getMinutes is not a function Error in JS


Borislav Hadzhiev

Wed Oct 20 20212 min read


Photo by Lucie Capkova

Solve - date.getMinutes is not a function Error #

The "date.getMinutes is not a function" error occurs when the getMinutes() method is called on a value that is not a date object. To solve the error, convert the value to a date before calling the method or make sure to only call the getMinutes() method on valid date objects.

typeerror date getMinutes is not a function

Here is an example of how the error occurs.

const date =; console.log(date); // ๐Ÿ‘‰๏ธ 1639... // โ›”๏ธ TypeError: date.getMinutes is not a function const result = date.getMinutes();

We called the function, which returns an integer and tried to call the Date.getMinutes() method on it, which caused the error.

To solve the error, make sure to only call the getMinutes() method on valid date objects.

const m1 = new Date().getMinutes(); console.log(m1); // ๐Ÿ‘‰๏ธ 8 const m2 = new Date('Sept 24, 22 13:20:18').getMinutes(); console.log(m2); // ๐Ÿ‘‰๏ธ 20

You can get a date object by passing a valid date to the Date() constructor.

Note that if an invalid date is passed to the Date() constructor, you would get NaN (not a number) value back.

const d1 = new Date('invalid').getMinutes(); console.log(d1); // ๐Ÿ‘‰๏ธ NaN

You can console.log the value you are calling the getMinutes method on and see if it's a valid Date object.

You could conditionally check if the value is a Date object in the following way.

const d1 = new Date(); if (typeof d1 === 'object' && d1 !== null && 'getMinutes' in d1) { const result = d1.getMinutes(); console.log(result); // ๐Ÿ‘‰๏ธ 11 }

Our if condition uses the logical AND (&&) operator, so for the if block to run, all of the conditions have to be met.

We first check if the d1 variable stores a value with a type of object, because dates have a type of object.

Then we check if the variable is not equal to null. Unfortunately, if you check the type of null - console.log(typeof null), you will get an "object" value back, so we have to make sure the value is not null.

The last thing we check for is that the object contains the getMinutes property.

Then we know we can safely call the getMinutes method on the object.

Join my newsletter

I'll send you 1 email a week with links to all of the articles I've written that week

Buy Me A Coffee