check time with php

Asked

Viewed 432 times

1

How to check if the time entered in the input is more than 24?

I tried so:

if ((strtotime($hora) > "24:00:00")) {

    echo "a hour não pode ser maior que 24";
}
  • 1

    it would not be easier to make an explosion in the var delimiting : and check hour, minute and second?

  • or still use native function DateTime?

  • 2

    $strHora = substr("$hour", 0,2); If ($strHora>24){ echo "the hour cannot be greater than 24"; }

  • I think you mean more than 11:59:59, if it’s time of day, because after that it’s 12:00... Unless you’re doing "hours counted," like I worked "80 hours this week only". If you can explain which of these is your case then I will create an answer that is correct for your case.

  • I need to buy 2 hours, ahora with the time that is in the BD format 00:00:00, I need to know if the hour of achievement and smaller.

  • Friend @leo’s suggestion should work perfectly for your case.

  • @Marcelobonifazio can post an example? ai already mark your answer

  • @Leocaracciolo put with answer for me to score

Show 3 more comments

1 answer

0


$strHora = substr("$hora", 0,2);
If ($strHora>24){
echo "a hour não pode ser maior que 24";
}

mas o correto seria 

$strHora = substr("$hora", 0,2);
If ($strHora>=24){
echo "a hour não pode ser maior que 24";
}

já que ninguém diz 24:00:00 e sim zero hora, então no if seria $strHora > 23 

  • ok, more how do I compare 2 dates? like if 10:00 and less than 20:00.

  • 2

    change the time in timestamp

  • 1

    this was not specified in question rs

  • @Marcelobonifazioi know, the doubt has now arisen hahahah, more vlw

Browser other questions tagged

You are not signed in. Login or sign up in order to post.