How can I select rows that are older than a specific date?

Viewed 2259

I have tried using:

SELECT * FROM dbo.admin_IVM_ITEMMAST WHERE LSTSAL_DATE <= '2016-09-31 00:00:00.000'

But when I execute the query i get this error.

Error:

Msg 242, Level 16, State 3, Line 1 The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.

The column name is: LSTSAL_DATE and a typical string inside the column is: 2013-05-02 00:00:00.000

2 Answers

There are only 30 days in september!

SELECT * FROM dbo.admin_IVM_ITEMMAST WHERE LSTSAL_DATE <= '2016-09-30 00:00:00.000'

you can select the date you or from access form's textbox and 20 can be written any number you want if you put 50 instead of 20 you will get people who are older than 50 years. 20 in the code could be a variable to select specific age by number

`SELECT *

FROM Table Name

WHERE ((Year(Now())-Year(date)>20)); `

Related