从mysql datetime向日期添加10分钟并将其与现在的时间进行比较 [英] Adding 10 minutes to a date from mysql datetime and comparing it to the time now

查看:456
本文介绍了从mysql datetime向日期添加10分钟并将其与现在的时间进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何从mysql数据库中获取10分钟的时间,字段结构为datetime.

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

当前代码

$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 );

这将显示 2011-09-07 13:53:43<上次登录时间 2011-09-07 03:56:15<现在时间 2611<结束时间-应该是最后10分钟的时间"

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 "

我无法确定如何从mysql的时间/日期中添加10分钟,我需要这样做,然后设置一个命令来比较现在和上次登录的时间,因此如果已经10分钟,我可以停止用户试图再次登录!

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!

感谢您的帮助

推荐答案

$timeoflastlogin不是不是Unix时间戳,而是 string -因此您不能使用它作为strtotime的$now参数.这应该起作用:

$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 ) );

或更简单:

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

这篇关于从mysql datetime向日期添加10分钟并将其与现在的时间进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆