douruye5092 2014-04-18 23: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 23: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 )  );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程