I'm trying to get an SQL query to select all records from last month, I have this which from looking numerous places is exactly what I should need, and should work:
SELECT *
FROM orders
WHERE DATEPART(yy,DateOrdered) = DATEPART(yy,DATEADD(m,-1,GETDATE()))
AND DATEPART(m,DateOrdered) = DATEPART(m,DATEADD(m,-1,GETDATE()))
However I keep getting the error:
#1305 - FUNCTION retail.DATEPART does not exist
The query I'm using is word for word from other answers on here, yet I'm getting this error.
Thank you for any help -Tom
DATEPART is a Transact-SQL function, usable with Microsoft SQL Server. From the question tags, I assume you are using MySQL as your Database Management System.
Take a look at MySQL DATEDIFF