user3630473 user3630473 - 1 year ago 82
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 Source

It should be:

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

Don't check for year in your where clause.


Simple: use

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

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download