MYSQL将时间戳转换为月份 [英] MYSQL Convert timestamp to Month

查看:680
本文介绍了MYSQL将时间戳转换为月份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对mysql日期函数有这个问题.

I have this certain problem about mysql date functions.

我正在尝试将本月"的值与数据库中给定的时间戳进行比较.

I'm trying to compare the value of THIS MONTH to the given timestamp in database.

例如,今天的月份为6月,时间戳为 1369967316

For example, month today is june, and the timestamp is 1369967316

我正在尝试确定该时间戳记是否在6月.

And I'm trying to determine if that timestamp is in month of june.

$query = db_query("SELECT * FROM users WHERE MONTH(FROM_UNIXTIME(CURDATE())) = MONTH(1369967316)");

//count total members this mont
$members_month = $query->rowCount();

因此,如果我使用rowCount,则$ members_month的值应为1.

so if I used the rowCount, the $members_month should have the value of 1.

不幸的是,它不起作用. 任何帮助将不胜感激.

Unfortunately it doesn't work. Any help would be appreciated.

好吧,我看到了一些与我的问题相关的答案,但是并没有达到目的或者我没有很好地运用它.

Well I saw some answers that some kind of relevant to mine but it doesn't hit the spot or I didn't applied it well.

mysql从时间戳获取月份不起作用

如何在反对unixtimestamp(bigint)列的where子句

推荐答案

这对我有用:

mysql> SELECT MONTH(FROM_UNIXTIME(1369967316));
+----------------------------------+
| MONTH(FROM_UNIXTIME(1369967316)) |
+----------------------------------+
|                                5 |
+----------------------------------+

您的问题很可能来自以下事实:1369967316是5月30日,而不是6月(如您期望的那样),从而导致MONTH(CURDATE())的不平等.

Your issue is likely coming from the fact that 1369967316 is May 30th, not June (as you expect), thus resulting in an inequality with MONTH(CURDATE()).

mysql> SELECT FROM_UNIXTIME(1369967316);
+---------------------------+
| FROM_UNIXTIME(1369967316) |
+---------------------------+
| 2013-05-30 22:28:36       |
+---------------------------+

这篇关于MYSQL将时间戳转换为月份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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