字符串编号比较

时间:2019-01-05 08:22:09

标签: php

我有一个包含时间和日期的变量:

$a = "2018-10-19 19:04:53";

现在,我需要检查年份是否大于或等于2019,然后如果月份大于01(一月),然后是日期。我尝试使用strpos,但是没有用。

if (strpos($a, 2018>) !== false) {
        echo 'true';

3 个答案:

答案 0 :(得分:3)

$a=strtotime('2018-10-19 19:04:53');
$b=strtotime('2019-01-31');

if ($b > $a) {
  echo "True";
}

答案 1 :(得分:1)

$a = "2018-10-19 19:04:53";
$year=date("Y",strtotime($a));  // output- 2018
$month=date("m",strtotime($a)); // output- 10
if($year>=2019 && $month>01){

       echo 'your code';
}

答案 2 :(得分:1)

您可以使用以下PHP代码:

$a = "2018-10-19 19:04:53";
if (date("Y",strtotime($a)) >= 2018 && date("m",strtotime($a)) > 01) {
    echo 'True';
}