INDRESH KHANDELWAL
INDRESH KHANDELWAL

Reputation: 129

How to put month from date in where clause in sql query

I have table in database which has fields -(EId,PId,Date,Time).

I want to select all the fields from this table where month < 5.To be more elaborate I want entries which were entered into the table before month 5.

Please help me write this sql query. Thanks :)

Upvotes: 0

Views: 3431

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 522712

Use MONTH() and also remember to restrict the year in the WHERE clause:

SELECT *
FROM yourTable
WHERE MONTH(Date) < 5 AND YEAR IN (...)

Upvotes: 1

Related Questions