This question already has an answer here:
这个问题在这里已有答案:
- Select current months records mysql from timestamp column 8 answers
- 从时间戳列8答案中选择当前月份记录mysql
- How do I get the first day of the current month? 13 answers
- 我如何获得当月的第一天? 13个答案
How can I select Current Month records from a table of MySql database??
如何从MySql数据库表中选择当前月记录?
Like now current month is January. I would like to get records of January Month, Where data type of my table column is timestamp
.I would like to know the sql query.
像现在这个月是1月。我想得到1月份的记录,其中我的表列的数据类型是时间戳。我想知道sql查询。
Thanks
谢谢
3 个解决方案
#1
40
This query should work for you:
此查询应该适合您:
SELECT *
FROM table
WHERE MONTH(columnName) = MONTH(CURRENT_DATE())
AND YEAR(columnName) = YEAR(CURRENT_DATE())
#2
20
Check the MySQL Datetime Functions:
检查MySQL日期时间函数:
Try this:
尝试这个:
SELECT *
FROM tableA
WHERE YEAR(columnName) = YEAR(CURRENT_DATE()) AND
MONTH(columnName) = MONTH(CURRENT_DATE());
#3
0
Try this query:
试试这个查询:
SELECT *
FROM table
WHERE MONTH(FROM_UNIXTIME(columnName))= MONTH(CURDATE())
#1
40
This query should work for you:
此查询应该适合您:
SELECT *
FROM table
WHERE MONTH(columnName) = MONTH(CURRENT_DATE())
AND YEAR(columnName) = YEAR(CURRENT_DATE())
#2
20
Check the MySQL Datetime Functions:
检查MySQL日期时间函数:
Try this:
尝试这个:
SELECT *
FROM tableA
WHERE YEAR(columnName) = YEAR(CURRENT_DATE()) AND
MONTH(columnName) = MONTH(CURRENT_DATE());
#3
0
Try this query:
试试这个查询:
SELECT *
FROM table
WHERE MONTH(FROM_UNIXTIME(columnName))= MONTH(CURDATE())