0

I'm stuck with this, I'm trying this code with phalcon framework:

if(strtotime("+5 minutes",$quarantine->getFirst()->datecolumnvalue)>time()){...}

But doesn't work, always give false. I cannot do it with just MySQL because PHQL from phalcon doesn't support it, so I just need a PHP comparison. Regards.

danielmg
  • 211
  • 3
  • 13

2 Answers2

1

This did the trick :) , just an strtotime missing.

if(strtotime("+5 minutes", strtotime($quarantine->getFirst()->datecolumnvalue))>time()){...}
danielmg
  • 211
  • 3
  • 13
0

Your logic is simply backwards. Just flip > to <:

if (strtotime("+5 minutes",$quarantine->getFirst()->datecolumnvalue) < time()) {
    ...
}

You want cases where, even if you add 5 minutes to the database time, it's still LESS THAN (before) the current time.

mopo922
  • 6,293
  • 3
  • 28
  • 31
  • @danielmg Are you sure you have some records that happens less than 5 minutes ago? – mopo922 May 04 '15 at 17:11
  • Yes I'm sure, i have HEIDISQL on all the time, checking the data. I'm working in local so is easy. I think the problem is with the comparison, maybe the data type. Cannot be the timezone because I configured both (php and mysql) to use by default GMT0. Anyway by now I'm working just with one record set with CURRENT_TEMP() in another function that I just call in purpose when I want to update the timing. – danielmg May 04 '15 at 19:06
  • However I need to check wheter is less or more than 5 minutes, in this IF statement in concreet I want to check if passed more than 5, but It activates wether is more than 5, equal or less, so Is obviously a problem with the comparison, probably I need to cast the type... – danielmg May 04 '15 at 19:06
  • @danielmg `strtotime` and `time` return the same data type. I think it's more likely a problem with the underlying data (`datecolumnvalue`). – mopo922 May 04 '15 at 19:45
  • For example last value stored when I was at work was 17:04:51 , you can see the format there. – danielmg May 04 '15 at 23:11
  • @danielmg Are you including the date? Like `2015-05-04 17:04:51` – mopo922 May 05 '15 at 01:37
  • I store it as TIME no as DATETIME, so just 09:57:04. I've printed the value of the database+ the minutes = 1430820121,but the function time() prints 1430819812, what Is ok because still database+5 minutes is more than the actual time because I updated the value to current_time. But what i notice is that the value of the database+ the minutes is also increasing in seconds as the time() function....It shoud just add 5 minutes and thats all, why is increasing in seconds as well :S – danielmg May 05 '15 at 10:00