Jump to content

Archived

This topic is now archived and is closed to further replies.

xyn

Time...

Recommended Posts

Hi Guys,
I am looking into making time bans, allowing my mods to ban someone for
either x hours, x days, or x minutes, What would be the easiest way?
I've been thinking bout "d/m/y" and "H:i:s" but i don't think it will work...

Share this post


Link to post
Share on other sites
[quote author=xyn link=topic=109471.msg441308#msg441308 date=1159219415]
Hi Guys,
I am looking into making time bans, allowing my mods to ban someone for
either x hours, x days, or x minutes, What would be the easiest way?
I've been thinking bout "d/m/y" and "H:i:s" but i don't think it will work...
[/quote]

Use timestamps. Don't store the times in the database as a formatted date. Timestamps can then be compared more easily in the code AFTER you run your SQL queries. Maybe something like this....

[code]<?php

$query = $db->query("SELECT * FROM banned WHERE user = $userinfo[username]");
$btime = $db->fetch_array($query);

$time = time();
$maxbtime = ($time - $btime[ban_time]);
$hours = date("h",$maxbtime);
$minutes = date("i",$maxbtime);

if(YOUR CONDITIONAL CRITERIA HERE){

echo'Hey punk, you\'re still banned from these here forums!!';

}
?>[/code]

Share this post


Link to post
Share on other sites
If you want to ban for $x days
[code]
$ban_until = strtotime ("+$x days);
[/code]
Similarly, to ban for $x hours
[code]
$ban_until = strtotime ("+$x hours);
[/code]

As Caesar suggests, store the resulting $ban_until in the table (integer field will do it)

You can see if the ban is still in effect by comparing with time() function, which gives the current timestamp

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.