5

How would I construct a statement like if current time ($time) is more than 30 seconds past time ($djs['currenttime'])? Would it be something like

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

Thanks :).

Mike B
  • 31,886
  • 13
  • 87
  • 111
Sam
  • 6,616
  • 8
  • 35
  • 64
  • it would depend on the date format of variables. You could have a look at PHP function date_diff http://www.php.net/manual/en/function.date-diff.php – vsr Jun 16 '10 at 12:46

2 Answers2

6

The 30 seconds you are struggling with it's simply a +30 added on the conditional incrementing the value of $djs['currenttime'].

You can use the time() function to get the actual time. I'm assuming that djs['currenttime'] is a value extracted from the database. Therefore the comparison would be the following:

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

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

Juan Cortés
  • 20,634
  • 8
  • 68
  • 91
  • Ah, I see, so it is all based in seconds, not milliseconds or something smaller. Thankyou. – Sam Jun 16 '10 at 12:45
  • If you were using microtime instead of time, it would be using microseconds but time itself uses seconds as the unit. – Juan Cortés Jun 16 '10 at 12:51
3
if ($time > ($djs['currenttime'] + 30))

Assumes that both values are actual timestamps and not formatted strings

Mark Baker
  • 209,507
  • 32
  • 346
  • 385