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?
To select all entries from a particular month in MySQL, use the monthname() or month() function.
You can group month and year with the help of function DATE_FORMAT() in MySQL. The GROUP BY clause is also used.
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.
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.
Simply use MONTH() and YEAR():
SELECT * FROM Project WHERE MONTH(DueDate) = 1 AND YEAR(DueDate) = 2010
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With