添加30分钟到datetime php / mysql [英] adding 30 minutes to datetime php/mysql

查看:113
本文介绍了添加30分钟到datetime php / mysql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在mysql中有一个datetime字段(endTime)。我使用gmdate()来填充这个endTime字段。



存储的值就像2009-09-17 04:10:48。我想在这个结束时间添加30分钟,并将其与当前时间进行比较。即)用户被允许在他的endTime内30分钟内完成某项任务。在他的endTime的30分钟后,我不应该允许他做一个任务。



我该如何在php中执行?



我使用gmdate来确保没有区域差异。



提前感谢

解决方案

如果您使用 MySQL 你可以这样做:

  SELECT'2008-12-31 23:59:59'+ INTERVAL 30 MINUTE; 



对于纯PHP解决方案,使用 strtotime

  strtotime('+ 30分钟',$ yourdate); 


I have a datetime field (endTime) in mysql. I use gmdate() to populate this endTime field.

The value stored is something like 2009-09-17 04:10:48. I want to add 30 minutes to this endtime and compare it with current time. ie) the user is allowed to do a certain task only 30 minutes within his endTime. After 30 minutes of his endTime, i should not allow him to do a task.

how can i do that in php?

i'm using gmdate to make sure there are no zone differences.

Thanks in advance

解决方案

If you are using MySQL you can do it like this:

SELECT '2008-12-31 23:59:59' + INTERVAL 30 MINUTE;


For a pure PHP solution use strtotime

strtotime('+ 30 minute',$yourdate);

这篇关于添加30分钟到datetime php / mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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