If the current time exceeds 30 seconds for the last time period X (from the database)

How can I build an operator, for example, if the current time ($ time) has passed more than 30 seconds ( $djs['currenttime'] )? It would be something like

if ( $time => $djs['currenttime'] )? I can not figure it out with 30 seconds .. :).

Thanks:).

+4
source share
2 answers

30 seconds you're struggling with, just add +30 to the conditional value, increasing the value of $djs['currenttime'] .

You can use the time() function to get the actual time. I assume djs['currenttime'] is a value retrieved from the database. Therefore, the comparison will be as follows:

 if(time() > $djs['currenttime'] + 30){ //actions here; } 

time() returns the number of seconds since January 1, 1970 00:00:00 GMT, therefore, for this, the format of the variable $djs['currenttime'] must also be a unix timestamp. If not, you need to first convert one of them to the appropriate format.

+5
source
 if ($time > ($djs['currenttime'] + 30)) 

Both values โ€‹โ€‹are assumed to be valid timestamps and not formatted strings

+3
source

Source: https://habr.com/ru/post/1312964/


All Articles