Pergunta

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

Foi útil?

Solução 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.

Outras dicas

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
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top