2011-06-21 32 views
0

我需要添加3小时或日期3小时(GMT + 3)后( 'H:I:S')我的查询如何在日期中添加+3('H:i:s')?

$query2="SELECT location FROM course where Dr_ID = 2 AND time_start <= '".date('H:i:s')."' and time_end > '".date('H:i:s')."'"; 

,并感谢

+0

'time_start'字段是什么类型? – zerkms

+0

@zerkms:您的解决方案与我将要提供的解决方案相同......为什么要删除它? – mpen

+0

@Mark:因为我忘记了mysql中的'time'类型:-S – zerkms

回答

1

可以acheive通过使用time()函数,然后添加秒数来调整DateTime变量。

在这种情况下,要加3个小时,这是

3 Hours = 60 Seconds X 60 Minutes X 3 

所以,time() + (3*60*60)将做的工作

这里是更新查询

$query2="SELECT location FROM course 
    where Dr_ID = 2 
    AND time_start <= '".date('H:i:s')."' 
    and time_end > '".date('H:i:s',time()+(3*60*60))."'"; 
1

date("H-i-s", mktime(date('H')+3, date('i'), date('s'), 0, 0, 0));

1

您可以尝试date("h:i:s" ,strtotime("+3 hours"));

这应该对你有所帮助