添加30分钟到datetime php / mysql [英] adding 30 minutes to datetime php/mysql
问题描述
存储的值就像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屋!