Get records of current month

MysqlSqlDateSelectTimestamp

Mysql Problem Overview


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

Mysql Solutions


Solution 1 - Mysql

This query should work for you:

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

Solution 2 - Mysql

Check the MySQL Datetime Functions:

Try this:

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

Solution 3 - Mysql

Try this query:

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionFoysal VaiView Question on Stackoverflow
Solution 1 - MysqlAman AggarwalView Answer on Stackoverflow
Solution 2 - MysqlSaharsh ShahView Answer on Stackoverflow
Solution 3 - MysqlankurView Answer on Stackoverflow