I want to check if date is not equal to 0000-00-00 00:00:00. How can I check it in javascript?
I checked with date !== null
but it is not working.
I want to check if date is not equal to 0000-00-00 00:00:00. How can I check it in javascript?
I checked with date !== null
but it is not working.
You can check "0000-00-00 00:00:00" with
Date.parse(date) // NaN
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse
Having 0000-00-00 00:00:00
suggest that you not deal with Date
object in JS but string comparing it in if
statement should do:
if (data !== '0000-00-00 00:00:00') { ....
Here is an example using ternary operators:
(date === '0000-00-00 00:00:00' ? exprIfTrue : exprIfFalse );
Also, below is an example using indexOf. - There are definitely a few ways to do this but not exactly sure what you're looking for with your use-case.
const zeroDate = '0000-00-00 00:00:00';
const realDate = '2020-10-13 00:04:05';
//check to see if indexOf '0000-00-00' exists in zeroDate string
// if true then log 'yes', if false then log 'no'
// this will log 'yes' since '0000-00-00' exists
(zeroDate.indexOf('0000-00-00') == 0 ? console.log('yes') : console.log('no') );
//same as above but for realDate string
//since there is no occurance of '0000-00-00' it will log 'no'
(realDate.indexOf('0000-00-00') == 0 ? console.log('yes') : console.log('no') );