php - 如何在php mysql中比较日期时间和时间

标签 php mysql datetime time

只有一个问题:是否可以比较日期时间格式和时间格式?

我有表employee_attendance(日期时间类型)和表employee_schedule(时间类型),这是为了确定员工是否迟到。

请检查我的代码。

$CheckInNew  = strtotime('2013-06-05 08:47:53');
$OnDutyTimeNew   = strtotime('08:00:00');

if($CheckIn > $OnDutyTimeNew){

// confirming that the employee is late

} else {

// confirming that the employee is NOT late

}

有什么想法吗?

谢谢

最佳答案

试试这个:

$CheckInNew  = date('B',strtotime('2013-06-05 08:47:53'));
$OnDutyTimeNew   = date('B',strtotime('08:00:00'));

if ($CheckInNew > $OnDutyTimeNew)
    echo 'late!';
else
    echo 'early!';

我将 be 用作 Internet Swatch 时间的关键字。有关更多信息,here's the link

更新: PHPFiddle

关于php - 如何在php mysql中比较日期时间和时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16929777/

相关文章:

php - Zend 工具创建操作无法识别模块中的 Controller

mysql - 检查带有 LIMIT 的 SELECT 语句是否返回所有行

mysql - 在两个 td 标签中显示日期时间

mysql - php5-msql 安装在 Ubuntu 上但未显示在 phpinfo.php 中

php - 在 PHP 中拆分字符串并获取最后一部分

php - 隐藏表单字段不存储变量

mysql - 如何检查 MySQL 触发器中 OLD.* 到 NEW.* 列中每个列的差异?

mysql - sql中查找不常见用户

mysql - SQL 和 DateTime - 如何选择在特定时间段内存在的所有行?

c# - 查找过去最近的日期