Pages: [1]   Go Down
Send this topic | Print
Author Topic: PHP time() compare  (Read 1039 times)
M0ZZA
A Man In A Trance...
Loyal 110MB Member
*******
Offline Offline

Posts: 2542


So yeah, I would like to be a moderator.


WWW
« on: December 06, 2008, 10:02:04 PM »

I am making a temporary banning system, but I dont know how to compare the time the user has been banned with the alloted ban duration


Say I wanted to ban them for 15 minutes, how would I check the time (stored in mysql database) with the current time ?

I know how to do all the SQL etc, its just the time bit im stumped on...
Logged

Confuser
Creator of eoCMS
Loyal 110MB Member
*******
Online Online

Posts: 3129


The Forum's Angel


WWW
« Reply #1 on: December 06, 2008, 10:39:40 PM »

well when u ban them insert the time() as well. Then when checking compare the 2 times eg
Code:
$time = time() - $database['time'];
if($time > 900) {
//unban them
}
900 is 15mins in seconds
or you could just change the 900 to (60 * number of mins)
Logged

tpog
Super Authority member
******
Online Online

Posts: 1540


WWW
« Reply #2 on: December 06, 2008, 10:56:08 PM »

strtotime is quite useful as well, lets you get a unix time stamp for the comparison, using strings, e.g.
Code:
strtotime("-15 min");
Logged
M0ZZA
A Man In A Trance...
Loyal 110MB Member
*******
Offline Offline

Posts: 2542


So yeah, I would like to be a moderator.


WWW
« Reply #3 on: December 06, 2008, 11:32:07 PM »

Thanks, that worked great !
Logged

Pages: [1]   Go Up
Send this topic | Print
Jump to: