MySQL 获取当月记录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21276975/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 19:53:01  来源:igfitidea点击:

Get records of current month

mysqlsqldateselecttimestamp

提问by Foysal Vai

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.

就像现在当月是一月。我想获取一月的记录,我的表列的数据类型是哪里timestamp。我想知道 sql 查询。

Thanks

谢谢

回答by Aman Aggarwal

This query should work for you:

此查询应该适合您:

SELECT *
FROM table
WHERE MONTH(columnName) = MONTH(CURRENT_DATE())
AND YEAR(columnName) = YEAR(CURRENT_DATE())

回答by Saharsh Shah

Check the MySQL DatetimeFunctions:

检查MySQL 日期时间函数:

Try this:

尝试这个:

SELECT * 
FROM tableA 
WHERE YEAR(columnName) = YEAR(CURRENT_DATE()) AND 
      MONTH(columnName) = MONTH(CURRENT_DATE());

回答by ankur

Try this query:

试试这个查询:

SELECT *
FROM table 
WHERE MONTH(FROM_UNIXTIME(columnName))= MONTH(CURDATE())