开发者

Comparing timestamp with date variable (MySQL and PHP)

Any help is high开发者_如何学Goly appreciated.

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. "'


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') . "'

or to be more precise:

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


Simply

SELECT [...] WHERE '$you_var' = date(`timestamp_column`);

MySQL date() function


You could always convert the timestamp to a formatted date.

SELECT FROM_UNIXTIME(1358871753,'%Y %D %M');

Produces: 2013 22nd January

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜