doudou_3636 2018-02-09 03:47
浏览 33
已采纳

任何人都可以帮我解决这个问题:可恢复的致命错误:类DateTime的对象无法转换为字符串[duplicate]

This question already has an answer here:

I have prob with the time after the subtraction to be inserted into database

$time = new DateTime('08:10:00');
$timein = new DateTime('17:05:00');
$newtime = $timein->diff($time);
$sql = "UPDATE staff_attendance SET total_working_time='$result' WHERE id='$a_id'";
</div>
  • 写回答

1条回答 默认 最新

  • dongzai3917 2018-02-09 04:00
    关注

    You need to fetch difference and then convert to H:i:s, like this:

    $hour = $newtime->format('%h');
    $minute = $newtime->format('%i');
    $second = $newtime->format('%s');
    
    $year = $newtime->format('%y');
    $month = $newtime->format('%m');
    $day = $newtime->format('%d');
    
    $time = $hour.':'.$minute.':'.$second; // H:i:s
    

    https://paiza.io/projects/QKxRTpDEo6zRjooQAfdONQ?language=php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 这个公式写进SIMULINK中的function模块的代码中应该是什么样的
  • ¥15 javaweb登陆的网页为什么不能正确连接查询数据库
  • ¥15 数学建模数学建模需要
  • ¥15 已知许多点位,想通过高斯分布来随机选择固定数量的点位怎么改
  • ¥20 nao机器人语音识别问题
  • ¥15 怎么生成确定数目的泊松点过程
  • ¥15 layui数据表格多次重载的数据覆盖问题
  • ¥15 python点云生成mesh精度不够怎么办
  • ¥15 QT C++ 鼠标键盘通信
  • ¥15 改进Yolov8时添加的注意力模块在task.py里检测不到