【问题标题】:How to add time in PHP?如何在 PHP 中添加时间?
【发布时间】:2015-05-11 06:24:01
【问题描述】:

我从数据库中获取各种行(该列被格式化为日期时间)并将其格式化为仅时间。现在我想将所有行添加到一个 PHP 变量中,我该如何实现呢?

 $total_time = $this->fetchTime();

 public function fetchTime(){
    $catch = 0;
    $db = $this->getConn();
    $statement = $db->prepare("SELECT log_in FROM attendance");
    $statement->execute();
    while ($result = $statement->fetch()){
       $catch += $result[0]; //This is the part where I do not know how to add time
    }
    return $catch;

 }

【问题讨论】:

  • 你能显示一些代码吗? (例如您如何获取行,以及您遇到问题的行)
  • 向我展示你的努力?
  • 已编辑。有努力。

标签: php datetime


【解决方案1】:

这可能对你有帮助

public function fetchTime(){
    $catch = "";
    $db = $this->getConn();
    $statement = $db->prepare("SELECT log_in FROM attendance");
    $statement->execute();
    while ($result = $statement->fetch()){
       $catch.= $result[0]; //This is the part where I do not know how to add time
    }
    return $catch;

 }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-11-30
    • 1970-01-01
    • 1970-01-01
    • 2011-01-31
    • 1970-01-01
    相关资源
    最近更新 更多