Linked Questions

120 votes
4 answers
91k views

Is there a way to check if a variable is a Date in JavaScript? [duplicate]

I was wondering if there is any way to check if an object is specifically a Date in JavaScript. isType returns object for Date, which isn't enough for this scenario. Any ideas? Thanks!
Kyle Hotchkiss's user avatar
3 votes
1 answer
59 views

Identifying a function name or property in Javascript [duplicate]

I'm using an npm module that throws an empty function i.e. UnauthorizedException upon error. I want to be able to identify the function thrown so i can handle it accordingly function ...
aldred's user avatar
  • 853
2213 votes
56 answers
1.6m views

Detecting an "invalid date" Date instance in JavaScript

I'd like to tell the difference between valid and invalid date objects in JS, but couldn't figure out how: var d = new Date("foo"); console.log(d.toString()); // shows 'Invalid Date' console.log(...
orip's user avatar
  • 76k
92 votes
1 answer
164k views

Checking if a date is valid in javascript [duplicate]

Possible Duplicate: Detecting an “invalid date” Date instance in JavaScript Is there is a function IsDate() in javascript?
Guilherme Costa's user avatar
8 votes
3 answers
5k views

Typescript: isNaN not accepting Date Object

const isObjectClass = (value: any, className: any) => (Object.prototype.toString.call(value) === `[object ${className}]`); export const isDate = (value: any) => isObjectClass(value, 'Date'); ...
lch's user avatar
  • 5,001
2 votes
3 answers
7k views

Getting Date and/or checking for it in JSON Object?

I have a JSON object that can (is) storing a Date (and/or any other JS object) but I'm not sure how to get it out once it's in it. For example I have this sample code, but it's not working: for(var ...
Oscar Godson's user avatar
  • 32.9k
4 votes
2 answers
670 views

d3.js filter() not displaying expected results

The filter command is not working as I expected. How would I refactor the code to get the requested output? In the .filter((d,i) => condition) syntax, d is an object with the x (date/time string) ...
crashwap's user avatar
  • 3,001
0 votes
2 answers
2k views

Create a new Date for any specific timezone

I am using Google Apps Script to check and re-format date data from some Google Sheets. But the problem is the result shows the times for the user who run the code. I want to show the date for any ...
Amir Hossain's user avatar
4 votes
2 answers
1k views

md- datePicker - Date instance error always

I am getting this error The ng-model for md-datepicker must be a Date instance. Currently the model is a: string. I am using moment.. in view <md-datepicker ng-model="Model.currentContact....
Alex's user avatar
  • 398
0 votes
2 answers
2k views

typeof !== "undefined", comparing dates, new Date, Math.min / What is wrong with this simple js code?

This code is on my nodeJS server. Every time the server gets to it, it crashes. Don't know what's wrong... Could someone help me? dateArray[11], dateArray[12] and dateArray[13] are either empty or ...
Emilio's user avatar
  • 1,364
0 votes
2 answers
4k views

How to use JavaScript to tell if a value is a date

I have a table of data that needs to be sorted and in order to do so, I have to determine the datatype of the columns: numeric, text, or date. And no, I never know what the datatype of column will be ...
Eric Cooper's user avatar
1 vote
3 answers
985 views

Is there a way to check for just a plain vanilla javascript object as opposed to any other special kind of object (i.e. Date)?

I tried using instanceof but it can't differentiate between {}, [], and Date. For example, If I want to make an if tree that goes like this: function foo(someVar){ if (/*someVar is an {}*/) { } ...
user avatar
1 vote
2 answers
605 views

Why is date instanceof Date returning false while all other date checks are returning true?

Using: Node, Prisma and Jest. I have a value that is acting like a Javascript date in everyway other than the instanceof Date check. Here is the code that I've used to check if it's a date. const ...
shmuels's user avatar
  • 1,463
0 votes
1 answer
908 views

Save dates to local storage

Im building a calendar with a synced todo list. I am trying to save a specific date based on the user input to local storage. At the moment the todo is saved to local storage and is presented in a ...
Miranda Nilhag's user avatar
0 votes
1 answer
781 views

Conditionally formatting dates in Angular

I have a property that I am displaying on an angular template which may or may not be a date. If it is a date, I would like to format it but if it's not, I just want to show the value. This is what ...
cooper's user avatar
  • 437

15 30 50 per page