Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

time(); Function

Featured Replies

Hi guys,

 

 

Im setting the time using time(); in my mysql database, how can i workout 300 seconds from the current time on the database?

 

if($data['last_active'] < time() -300) {

}

 

I figured it will be something simler to the above?

  • Author

What format is $data['last_active'] in?

 

Thats just demo text, its basicly getting the current set time() from the colum last_active in the table members.

 

I want to work out, has 5 minutes past from the time that was set on user login in the database

Thats just demo text, its basicly getting the current set time() from the colum last_active in the table members.

 

I want to work out, has 5 minutes past from the time that was set on user login in the database

 

Ok, so what format is the variable you're comparing in? Is it a Unix timestamp or a date format?

  • Author

Ok, so what format is the variable you're comparing in? Is it a Unix timestamp or a date format?

 

 

timestamp..

 

Im trying to get mysql to search for any accounts with isonline='1' then check with the time() function in php if the lastactive field has been more than 5 minutes since the last entry of the time();

Ok, try this:

 

if (($lastActive + 300) < time()) {
 // timed out
}

 

Make sure you've set the timezone correctly before that code:

 

date_default_timezone_set('Europe/London');

Personally. I'd rather let MySQL do the heavy lifting for you.

Have a look at the TIMESTAMPDIFF() function.

$qry = "SELECT TIMESTAMPDIFF(MINUTE, last_active, NOW()) as last_logged_in FROM `table`";

This will return a number which you can then easily compare with php.

Obviously, you can also use clauses such as WHERE etc

  • Author

$this->last_active = $connect->mfq('SELECT * FROM mi5_members WHERE isonline="1"');

 if($this->last_active['lastactive'] < time()-(30)) {
 $connect->mq('UPDATE mi5_members SET isonline="0" WHERE isonline="1"');

}

 

The code above is not doing its job, What i need it to do is set any user that has isonline='1' to isonline="0" where the lastactive time has been more than 5 minutes.

$this->last_active = $connect->mfq('SELECT * FROM mi5_members WHERE isonline="1"');

 if($this->last_active['lastactive'] < time()-(30)) {
 $connect->mq('UPDATE mi5_members SET isonline="0" WHERE isonline="1"');

}

 

The code above is not doing its job, What i need it to do is set any user that has isonline='1' to isonline="0" where the lastactive time has been more than 5 minutes.

 

Try this

 

 

$this->last_active = $connect->mfq('SELECT * FROM mi5_members WHERE isonline="1"');

 if($this->last_active['lastactive'] > time()-(300)) {
 $connect->mq('UPDATE mi5_members SET isonline="0" WHERE isonline="1"');

}

  • Author

Try this

 

 

$this->last_active = $connect->mfq('SELECT * FROM mi5_members WHERE isonline="1"');

 if($this->last_active['lastactive'] > time()-(300)) {
 $connect->mq('UPDATE mi5_members SET isonline="0" WHERE isonline="1"');

}

 

Beat you to it! :p

 

Heres what i did:

 

$last_active = mysql_fetch_array(mysql_query('SELECT * FROM mi5_members WHERE isonline="1" AND lastactive < "'.time(-10).'"'));

	if($last_active['lastactive'] < time()-300) {
	mysql_query('UPDATE mi5_members SET isonline="0" WHERE lastactive < "'.time(-300).'"');
	}

 

And it works perfect ;D

Beat you to it! :p

 

Heres what i did:

 

$last_active = mysql_fetch_array(mysql_query('SELECT * FROM mi5_members WHERE isonline="1" AND lastactive < "'.time(-10).'"'));

	if($last_active['lastactive'] < time()-300) {
	mysql_query('UPDATE mi5_members SET isonline="0" WHERE lastactive < "'.time(-300).'"');
	}

 

And it works perfect ;D

 

Aw well lol just had my sign turned the wrong way but yea i was gonna tell u 300 means 5 mins :)

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.