How to Check Whether an Object is a Date ? Last Updated : 20 Jun, 2023 Comments Improve Suggest changes Like Article Like Report This article will show you how to check whether the given object is a Date or not. There are two methods to check for date objects, which are described below: Method 1: Using instanceof Operator The instanceof operator checks whether the prototype property of a constructor appears anywhere in the prototype chain of an object. In this case, it is used to check whether the object is an instance of the Date object or not. A true value means that it does match the object specified. The validity of the date in the Date object can be checked with the !isNan() function. It returns true if the date is not invalid. Syntax: object instanceof Date Example: JavaScript let str = new String('This is a string'); let num = new Number(25); let date = new Date('13-January-19'); let ans = (str instanceof Date) && !isNaN(str); console.log(ans); ans = (num instanceof Date) && !isNaN(num); console.log(ans); ans = (date instanceof Date) && !isNaN(date); console.log(ans); Outputfalse false true Method 2: Using Object.prototype.toString.call() Method The Object.prototype.toString.call() method is used to return the internal class property of an object in a string of the format '[object Type]'. This property is assigned internally during the creation of any object. This property can be checked for the Date object by comparing it with the string '[object Date]'. A true value means that it does match the object specified. The validity of the date in the Date object can be checked with the !isNan() function. It returns true if the date is not invalid. Syntax: Object.prototype.toString.call(object) Example: JavaScript let str = new String('This is a string'); let num = new Number(25); let date = new Date('13-January-19'); let ans = Object.prototype.toString.call(str) === '[object Date]' && !isNaN(str); console.log(ans); ans = Object.prototype.toString.call(num) === '[object Date]' && !isNaN(num); console.log(ans); ans = Object.prototype.toString.call(date) === '[object Date]' && !isNaN(date); console.log(ans); Outputfalse false true We have a complete list of JavaScript Date Objects, to check those please go through this Javascript Date Object Complete reference article. Comment More infoAdvertise with us S sayantanm19 Follow Improve Article Tags : JavaScript Web Technologies javascript-object javascript-date JavaScript-Questions +1 More Similar Reads How to check if one date is between two dates in JavaScript ? The task is to determine if the given date is in between the given 2 dates or not? Here are a few of the most used techniques discussed with the help of JavaScript. In the first approach, we will use .split() method and the new Date() constructor. And in the second approach we will use the .getTime( 3 min read How to check if the given date is weekend ? To check if a given date falls on a weekend in JavaScript, you can use the getDay() method on a Date object. This method returns a number representing the day of the week, where 0 is Sunday and 6 is Saturday.There are two methods to solve this problem which are discussed below: Table of ContentUsing 2 min read How to Convert Date to Another Timezone in JavaScript? Converting a date to another timezone in JavaScript means adjusting the local date and time to match the time in a different timezone. This ensures that the displayed time aligns with the selected timezone, often using built-in methods or external libraries.1. Using Intl.DateTimeFormat() and format( 2 min read How to check if date is less than 1 hour ago using JavaScript ? Given a date and the task is to check whether the given date is less than 1 hour ago or not with the help of JavaScript. Approach 1: Count the milliseconds of the difference between the current and prev_date.If those are greater than milliseconds in 1 hour, then it returns false otherwise returns tr 2 min read How to check a date is valid or not using JavaScript? To check if a date is valid or not in JavaScript, we have to know all the valid formats of the date. For ex - "YYYY/DD/MM", "DD/MM/YYYY", and "YYYY-MM-DD", etc. We have a given date format and we need to check whether the given format is valid or not according to the official and acceptable date for 3 min read How to get the day and month of a year using JavaScript ? Given a date and the task is to get the day and month of a year using JavaScript. Approach: First get the current date by using new Date().Use getDay() method to get the current day in number format, Map it to the day name.Use getMonth() to get the current month in number format, Map it to the month 2 min read How to calculate the date three months prior using JavaScript ? To calculate the date three months prior using JavaScript, we could use the getMonth() and setMonth() methods. In this article, we are going to learn how to calculate the date three months prior using JavaScript. ApproachFirst, select the date object.Then use the getMonth() method to get the months. 1 min read How to calculate the yesterday's date in JavaScript ? In this article, we will see how to calculate yesterdayâs date in JavaScript. To calculate yesterday's date, you need to have some basic ideas of a few methods of JavaScript. JavaScript getDate() MethodJavaScript setDate() MethodJavaScript getDate() Method: It is an inbuilt JavaScript function that 3 min read How to calculate minutes between two dates in JavaScript ? Given two dates and the task is to get the number of minutes between them using JavaScript. Approach: Initialize both Date object.Subtract the older date from the new date. It will give the number of milliseconds from 1 January 1970.Convert milliseconds to minutes. Example 1: This example uses the c 2 min read How to get the first day of the year in JavaScript ? Given a date/year and the task is to get the first day of the year using JavaScript. Approach 1: Use getFullYear() Method to get the year from the given date.Use the new Date() function to create the new date object using year, month, and day. Example: This example uses the getFullYear() method to g 1 min read Like