douruye5092 2014-04-18 15:01 采纳率: 100%
浏览 48
已采纳

php试图在sql中为变量添加时间

Time:

<?php echo date("h:i A", (strtotime($row_AllEvents['event_time'])));

I have this time in php for certain events and each event also has a specific limit. What I want to do is add the limit to the event time and output it

the limit is stored within a sql database

like time =8 limit = 3  //output 8 - 11 

This is what i have tried:

Time:

<?php echo date("h:i A", (strtotime($row_AllEvents['event_time'])+$duration));

Prints out:

Description:web Date:September 10th, 2009 Time:12:00 AM Location:canto Duration:24

Description:dave Date:June 6th, 2013 Time:02:00 AM Location:php 123 Duration:7

Description:kajhdgfajhsdgfkjahsgdfkjahsgdfkajhsgdfkajhsgdfkajhsgdkfjhagsdkjfhagsdjf Date:September 12th, 2013 Time:08:00 AM Location:funny Duration:45

Description:jack Date:April 15th, 2014 Time:01:00 AM Location:canto Duration:8

Description:mickey Date:April 15th, 2014 Time:04:00 AM Location:canto Duration:9

Description:high Date:April 15th, 2014 Time:03:00 PM Location:canto Duration:9

Description:george Date:April 17th, 2014 Time:03:00 AM Location:canto Duration:9

Description:minnie Date:April 17th, 2014 Time:08:00 AM Location:canto Duration:8

Description:donald Date:May 23rd, 2020 Time:04:12 AM Location:canto Duration:12

  • 写回答

1条回答 默认 最新

  • dongweng9474 2014-04-18 15:42
    关注

    You're almost there. You need to actually add the time in seconds to your value because that's the time the date function understands.

    I assume your $duration is a time in minutes, so you convert that to seconds by multiplying by 60. Or if it is hours, by 60 again.

    echo date("h:i A", strtotime($row_AllEvents['event_time']));
    echo ' to ';
    echo date("h:i A", strtotime($row_AllEvents['event_time']) + ( $duration * 60 )  );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部