I need to get rows from the database where the records are of one month. I tried this SELECT:
$result = mysql_query("SELECT * FROM my_table WHERE DATEPART('month', date_column)=11");
In database is a lot of rows that have a date in the 11. month, but i do not get any results. Can anyone help me? Thank!
Select rows with date range using DATE() function Date() function will extract the date part from the datetime expression in MySQL.
Definition and Usage. The DATEPART() function returns a specified part of a date. This function returns the result as an integer value.
You can use SQL statements to select rows from the database to display on your report. Selecting rows limits, or creates a subset of, the data in a table. You select rows by creating a row condition. You can select rows that have no data in a column.
To get the last record, the following is the query. mysql> select *from getLastRecord ORDER BY id DESC LIMIT 1; The following is the output. The above output shows that we have fetched the last record, with Id 4 and Name Carol.
There is no DATEPART
function in MySQL. Use MONTH(date_column)
or EXTRACT(MONTH FROM date_column)
instead.
SELECT * FROM my_table WHERE MONTH(date_column)=11
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