Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select by Month of a field

Tags:

How can I get records from my table using month/year? I have a table like this:

Name - varchar DueDate -datetime Status -boll 

DueDate is project due date, I want record corresponding to month/year, not full date, I mean record for specific month.

How can I do this in mysql?

like image 421
Pankaj Avatar asked Jun 08 '10 12:06

Pankaj


People also ask

How do I select data by month in SQL?

To select all entries from a particular month in MySQL, use the monthname() or month() function.

How do I Group A timestamp by month?

You can group month and year with the help of function DATE_FORMAT() in MySQL. The GROUP BY clause is also used.

How can I get month from date column in SQL?

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.

How do I get current month data in SQL query?

We can retrieve the current month value in SQL using the MONTH() and DATEPART() functions along with the GETDATE() function. To retrieve the name of the month functions in SQL such as DATENAME() and FORMAT() are used.


1 Answers

Simply use MONTH() and YEAR():

SELECT * FROM Project WHERE MONTH(DueDate) = 1 AND YEAR(DueDate) = 2010 
like image 122
Keeper Avatar answered Oct 05 '22 12:10

Keeper