比较时间戳和日期变量(MySQL和PHP) [英] Comparing timestamp with date variable (MySQL and PHP)

查看:178
本文介绍了比较时间戳和日期变量(MySQL和PHP)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们非常感谢您的帮助.

Any help is highly appreciated.

说我有一个带有timestamp列且值为"1305590400"的MySQL数据库,如何将其与PHP变量"2011-05-17"进行比较?我想完全忽略时间部分,只比较日期.

Say I have a MySQL database with a timestamp column with the value "1305590400", how can I compare that with a PHP variable of say "2011-05-17"? I want to completely ignore the time part and only compare the date.

目前,我正在尝试使其与以下对象一起使用,但未返回任何结果:

At the moment I am trying to get it working with the following but it returns no results:

WHERE  FROM_UNIXTIME('timestamp_column','%Y-%m-%d') = '" . $date. "'

推荐答案

您不会得到可能$date具有一定的时间偏移并且在您的时区中不等于00:00:00的结果.

You don't get results that probably $date has some time offset and is not equal to 00:00:00 in your timezone.

WHERE timestamp_column BETWEEN '" . strtotime($date) . "' AND '" . strtotime($date, '+1 day') . "'

或更准确地说:

    WHERE timestamp_column >= '" . strtotime($date) . "'
      AND timestamp_column < '" . strtotime($date, '+1 day') . "'

这篇关于比较时间戳和日期变量(MySQL和PHP)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆