如何减HH:MM时间戳从时间YYYY-MM-DD HH:mm:ss的时间戳

问题描述 投票:-1回答:1

我在我的表列Statestarttime两列包含时间戳HH:MM(14:21)格式和时间戳列包含时间戳YYYY-MM-DD HH:MM:SS(2019年2月4日14时22分47秒)格式。

我想找出HH这些列之间的区别:MM(00:01)

我已经写了下面的代码,但得到通知:在差异列中遇到的非合式数值

<?php while($row = mysqli_fetch_array($search_result)):?>
                <tr>
                    <td align="Center"><?php echo $row['id'];?></td>
                    <td align="Center"><?php echo $row['EmpID'];?></td>
                    <td align="Center"><?php echo $row['Date'];?></td>
                    <td align="Center"><?php echo $row['Username'];?></td>
                    <td align="Center"><?php echo $row['Computername'];?></td>
                    <td align="Center"><?php echo $row['State'];?></td>
                    <td align="Center"><?php echo $row['MinutesatState'];?></td>
                    <td align="Center"><?php echo $row['StateStarttime'];?></td>
                    <td align="Center"><?php echo $row['StateEndtime'];?></td>
                    <td align="Center"><?php echo $row['Timestamp'];?></td>
                    <td align="Center"><?php echo $row['StateStarttime']-$row['Timestamp'];?></td>
                </tr>
                <?php endwhile;?>
php mysql html5 mysqli
1个回答
3
投票

你可以使用这个,而不是硬编码的时间通过你的时候,它会工作...!

$time1 = date("h:i:s",strtotime("2019-02-04 14:22:47"));
$time2 = date("h:i:s",strtotime("14:21"));

echo date("h", strtotime($time1)-strtotime($time2));
© www.soinside.com 2019 - 2024. All rights reserved.