Jump to content

Time...


xyn

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...
Link to comment
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]
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.