Menu

gitpiper

isDateValid javascript Code Snippet in 2024

dateintermediate

Last Updated: 16 December 2024

Checks if a valid date object can be created from the given values.

  • Use the spread operator (...) to pass the array of arguments to the Date constructor.
  • Use Date.prototype.valueOf() and Number.isNaN() to check if a valid Date object can be created from the given values.
const isDateValid = (...val) => !Number.isNaN(new Date(...val).valueOf());
isDateValid('December 17, 1995 03:24:00'); // true isDateValid('1995-12-17T03:24:00'); // true isDateValid('1995-12-17 T03:24:00'); // false isDateValid('Duck'); // false isDateValid(1995, 11, 17); // true isDateValid(1995, 11, 17, 'Duck'); // false isDateValid({}); // false

javascript snippet similar to isDateValid For You in December 2024

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2024 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️