Jump to content


Photo

php, mysql and timestamps


  • Please log in to reply
1 reply to this topic

#1 Baiba

Baiba
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 06 May 2006 - 10:30 PM

i am stuck with this:

$id = (int)$_REQUEST['id'];
$blocktime = (int)$_REQUEST['blocktime'];
$blocktimesec =60*$blocktime;
$time=$db->GetOne("SELECT NOW()+".$blocktimesec);
$db->Execute("UPDATE useri SET user_perm='blocked',user_blocked_till= ".$time.", user_block_tot =".$blocktime." WHERE user_id=".$id."");


$blocktime is amount of minutes user will be blocked for
user_block_tot is db field where amount of minutes user will be blocked for is stored (as integer)
user_blocked_till is db field where time whom till user will be blocked is stored (as timestamp)

problem is that something is stored in user_blocked_till but seems that it is not the time of present moment increased by the minutes user is blocked for, maybe someone could help what is not right in my code to make this happen?

#2 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 07 May 2006 - 08:40 AM

using mysql INTERVAL might help you out, it's much easier.
Storing time using NOW() + INTERVAL add or sub

example:
mysql_query("select * from table where stampedtime < date_sub(now(), interval 5 minute)");

[a href=\"http://www.mysqlfreaks.com/statements/53.php\" target=\"_blank\"]http://www.mysqlfreaks.com/statements/53.php[/a]





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users