user3630473 user3630473 - 2 months ago 7
SQL Question

How do I find data from this day exactly one year ago?

Right now I have:

year(epe_curremploymentdate) = year(DATEADD(year, -1, SYSDATETIME()))


But that is giving me everything from last year. All I want is the data from today's date, one year ago.

Answer

It should be:

epe_curremploymentdate = DATEADD(year, -1, GETDATE())

Don't check for year in your where clause.

EDIT:

Simple: use

cast(epe_curremploymentdate AS DATE) = cast(DATEADD(year, -1,
  GETDATE()) AS DATE)

That is, if you are using SQL Server 2008 and above.