1
How do I identify that
01:00:00(AM) é maior que 23:00:00h
Is there a function in php where I set it?
UPDATE:
if('2015-02-20 23:00:00' < '2015-02-21 01:00:00'){ //TRUE }
1
How do I identify that
01:00:00(AM) é maior que 23:00:00h
Is there a function in php where I set it?
UPDATE:
if('2015-02-20 23:00:00' < '2015-02-21 01:00:00'){ //TRUE }
4
01:00:00
is not greater than 23:00:00
.
However, to identify if 21/02/2015 01:00:00
is greater than 20/02/2015 23:00:00
you can compare the timestamp. For example:
// mktime(hora, minuto, segundo, mes, dia, ano)
$timestamp1 = mktime(1, 0, 0, 2, 21, 2015);
$timestamp2 = mktime(23, 0, 0, 2, 20, 2015);
if ($timestamp1 > $timestamp2) {
echo date("d/m/Y H:i:s", $timestamp1) . ' é maior que ' . date("d/m/Y H:i:s", $timestamp2);
// 21/02/2015 01:00:00 é maior que 20/02/2015 23:00:00
}
I used the function mktime
just as an example. You can use any resource that returns the timestamp ( time
, strtotime
, ... ).
Good answer, only add an emphasis on the first line, because this is precisely the problem, "01:00:00 is not greater than 23:00:00" :) +1
I just did this check: if('2015-02-20 23:00:00' < '2015-02-21 01:00:00'){ //TRUE } worked out php understood that just add the date, thanks for the tips!
Browser other questions tagged php
You are not signed in. Login or sign up in order to post.
How are you treating it ? in what context it appears ?
– Isvaldo Fernandes
in conditions if the first hour 23 is > I do a , action of certain day, but anoite always the first hour will be higher and will perform
– raddx
It turns out that
01:00:00(AM)
nay is greater than23:00:00h
. However,22/2/2015 01:00:00(AM)
is indeed greater than21/2/2015 23:00:00h
. That is, as @Isvaldofernandes said, you still have to explain your context.– Caffé
Depending on the case, you can simply use the current date + extra hours to determine this.
– Isvaldo Fernandes
I just need to set that 23:00:00 is no greater than 1:00:00 at "dawn"
– raddx
Hi Rafael. The problem of "I just need to define" is that as already explained by @Caffé this statement (1 am is larger than 11 pm) will be true or false depending on the day to which each hour refers. Please edit the question and provide more details about how the data is captured and/or maintained, otherwise it’s really difficult for someone to help you figure out what you need.
– Luiz Vieira
Btw, slightly related question which may also be of some help: http://answall.com/questions/25594/formato-hora-12-vs-24
– Luiz Vieira