Php 时间比较的怪异行为

Php 时间比较的怪异行为,php,wordpress,date,Php,Wordpress,Date,我不明白我写的这段代码到底出了什么问题,为什么它有一种不直观的行为 if(($datav == 0) || ((strtotime($datav)) > (strtotime('01/01/2014')))) { echo 'yes'; } else if((strtotime($datav)) < (strtotime('01/01/2014'))) { echo 'no'; } if(($datav==0)| |((strotime($datav))>(str

我不明白我写的这段代码到底出了什么问题,为什么它有一种不直观的行为

if(($datav == 0) || ((strtotime($datav)) > (strtotime('01/01/2014')))) {
echo 'yes';
}

else if((strtotime($datav)) < (strtotime('01/01/2014'))) {
echo 'no';
        }
if(($datav==0)| |((strotime($datav))>(strotime('01/01/2014')){
回应“是”;
}
如果((标准时间($datav))<(标准时间('01/01/2014')){
回应‘否’;
}
$datav是一个日期变量,可以在我编写的wordpress表单中设置,也不能设置

发生的情况如下:如果没有设置日期(=0),代码会工作,它会回显“是”;如果日期已设置且在2014年1月1日之前,则该日期也有效,并回显“否”;但是,如果日期设置在2014年1月1日之后,则该日期不起作用,并回显“否”。 在第三种情况下,我肯定我设置了正确的日期(2014年1月1日之后的日期),因为我重复了它以检查它

我做错了什么?
谢谢大家。

您要传递给
$datav
的日期格式是什么?strotime对它使用的日期格式很挑剔。如果设置日期YYYY-MM-DD的格式,则它可以工作,否则,它将假定为MM/DD/YYYY。如果您只需调试变量和
strotime()
,例如:
var\u dump(strotime($datav))
等。您很快就会看到结果可能是
错误
或错误的时间戳……嗯,我怎么知道日期格式?不幸的是,我无法直接访问数据库,我认为wordpress可能会在表单和输出中将其更改为欧洲标准格式(dd/mm/yyyy)。无论如何,我只是在代码中写了2014-01-01而不是2014年1月1日,没有任何变化:/Thank Glavić,我会试试。对不起,我是php新手!
<?php

$datav = 0;

test('2014-01-01');

test('2015-01-01');

test('01/01/2013');

test('25/12/2014'); // fail because strtotime will resolve as 1970-01-01

function test($datav) {

    echo "Input Date: $datav = ";

    $timestamp = strtotime($datav);

    if ($datav == 0 || $timestamp > strtotime('01/01/2014')) {
        echo 'yes';
    } else if ($timestamp < strtotime('01/01/2014')) {
        echo 'no';
    } else {
        echo 'neither';
    }

    echo " - What strtotime thinks was input (".date('d-M-Y', $timestamp).")<br />";
}