Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get records of current month [duplicate]

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

like image 444
Foysal Vai Avatar asked Jan 22 '14 07:01

Foysal Vai


People also ask

How can I get current month data?

Using MONTH() and GETDATE() function to fetch current month In SQL, we use the GETDATE() method to retrieve the value of the current date which is today's date. Let us try executing a simple query statement using which we will retrieve the value of the current date using GETDATE() function.

How do you get the month from a timestamp field?

Use the MONTH() function to retrieve a month from a date/datetime/timestamp column in MySQL. This function takes only one argument – either an expression which returns a date/datetime/ timestamp value or the name of a date/datetime/timestamp column. (In our example, we use the start_date column of date data type).

How do I get data from a specific month in SQL?

To select all entries from a particular month in MySQL, use the monthname() or month() function. The syntax is as follows. Insert some records in the table using insert command. Display all records from the table using select statement.


1 Answers

This query should work for you:

SELECT * FROM table WHERE MONTH(columnName) = MONTH(CURRENT_DATE()) AND YEAR(columnName) = YEAR(CURRENT_DATE()) 
like image 129
Aman Aggarwal Avatar answered Sep 30 '22 13:09

Aman Aggarwal