SELECT row by DATEPART()

user1827257 picture user1827257 · Nov 15, 2012 · Viewed 75.8k times · Source

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!

Answer

MvG picture MvG · Nov 15, 2012

There is no DATEPART function in MySQL. Use MONTH(date_column) or EXTRACT(MONTH FROM date_column) instead.