Get records of current month [duplicate]

2019-02-03 08:18发布

问题:

This question already has an answer here:

  • Select current months records mysql from timestamp column 8 answers
  • How do I select between the 1st day of the current month and current day in MySQL? 13 answers

How can I select Current Month records from a table of MySql database??

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.

Thanks

回答1:

This query should work for you:

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


回答2:

Check the MySQL Datetime Functions:

Try this:

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


回答3:

Try this query:

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