比较日期("Ymd h:i:s");

Sam*_*Sam 2 php time conditional-statements

如何创建条件语句,如date("Ymd h:i:s"); 在日期之后超过30秒("Ymd h:i:s");.

我以前用过像date这样的东西("Ymd h:i:s"); <date("Ymd h:i:s"); + 30,但这似乎不起作用.

救命?

Fel*_*ing 10

使用strtotime()将它们转换为UNIX时间.

例如:

if(strtotime($date2) - strtotime($date1) > 30) {
    // $date2 is more than 30 seconds after $date1
}
Run Code Online (Sandbox Code Playgroud)

要么

if(abs(strtotime($date2) - strtotime($date1)) > 30) {
    // $dates are more than 30 second apart
}
Run Code Online (Sandbox Code Playgroud)