mysql当前时间加10分钟,从mysql datetime向日期添加10分钟并将其与现在的时间进行比较...

I can't figure out how to add 10 minutes to a time I am getting from mysql database the field structure is datetime.

Current code

$nowtime = date('Y-m-d h:i:s');

$timeoflastlogin = $db->gettime();

//ADD 10 MINS TO TIME LAST ATTEMPTED

$endtime = strtotime('+ 10 minutes', $timeoflastlogin );

//$endtime = date('Y-m-d h:i:s', strtotime('+ 10 minutes', $timeoflastlogin );

This displays "

2011-09-07 13:53:43 < time of last login

2011-09-07 03:56:15 < now time

2611< endtime - this is supposed to be time of last +10 mins "

I cannot work out how to add 10 mins to the time/date from mysql, I need to do this and then set a command to compare the time now and of last login so if it has been 10 minutes I can stop the user trying to login again!

Thanks for your help

解决方案

$timeoflastlogin is not a Unix timestamp but a string - so you can't use that as a $now parameter for strtotime. This should work:

$endtime = strtotime('+ 10 minutes', strtotime( $timeoflastlogin ) );

or easier:

$endtime = strtotime( $timeoflastlogin ) + 600; // 10 minutes == 600 seconds

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值