这是一个有效的PHP日期相等检查吗? [关闭]

Is this a valid PHP date equality check?

$zeroDate = date("0000-00-00 00:00:00");

if( date($someOtherDateString)==$zeroDate ) {
// . . . 
}

I'd be more comfortable testing true date/time values than strings that just look like date times.

I have two basic approaches for testing date quality. The first one is: are the variables equal (like the track you're on above, but not string tests). The second one is: is there a non-zero delta between the dates?

Try this:

// convert strings to time
$zeroDate = strtotime("0000-00-00 00:00:00");
$someOtherDate = strtotime("0000-00-00T00:00:00-00:00");

// sanity check on the data
var_dump($zeroDate);
var_dump($someOtherDate);

// Approach #1
if ($someOtherDate === $zeroDate) {
    print "They are equal
";
} else {
    print "They are not equal
";
}

// Approach #2
if (($someOtherDate - $zeroDate) === 0) {
    print "They are still equal
";
} else {
    print "There are not equal
";
}

Hope this helps!

No.Use the Unix timestamp instead to get an integer:

$zeroDate = date('U', "0000-00-00 00:00:00");

if( date('U', $someOtherDateString)===$zeroDate ) {
// . . . 
}