INDRESH KHANDELWAL INDRESH KHANDELWAL - 5 months ago 15
SQL Question

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 :)

Answer

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

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