문제

I need to check a date in PHP if it is bigger than the 00:00 hours of the next day. At the first sight I tried to use

if($date_variable<strtotime('+1day')){
   return true;
}else{
   return false
}

But what it's doing is in fact adding to time() (24*60*60)

Is there any solution to that?

P.S.: Im trying to avoid the use of date on +1day and backwards to UNIX without hours info

도움이 되었습니까?

해결책 2

Okay the accepted answer is now over three years old and since we got PHP5 and even now PHP7 we can do it much easier with the DateTime class. The DateTime class is a native PHP class. No further library is in need.

$oDateNow = new DateTime(); // Date now
$oDateTomorrow = new DateTime('tomorrow midnight'); // Date tomorrow midnight

$bResult = $oDateNow < $oDateTomorrow ? true : false;

The DateTime class accepts all parameters the strtotime() function also accepts.

다른 팁

You can use:

if($date_variable<strtotime('midnight tomorrow')){
   return true;
}else{
   return false
}

You can try using mktime() like this :

if($date_variable<mktime(0,0,0, date('m'), date('d')+1, date('Y')){
   return true;
}else{
   return false
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top