• ### Question

• Hello,

can anybody give me an idea how to find same date 2 years ago from 2017-05-30, get this date 2015-06-01

thanks a lot

Monday, September 9, 2019 6:43 PM

### All replies

• DECLARE @d date = '2017-05-30';

A Fan of SSIS, SSRS and SSAS

Monday, September 9, 2019 7:03 PM
• Hi,

You can also use like below:

```DECLARE @d date = '2017-05-25';

Note: Suggested some of the many ways that are easy to understand and implement.

Thanks,
Arulmouzhi

Tuesday, September 10, 2019 4:01 AM
• Hi  Jasmin,

I'm not sure how you get the date' 2015-06-01', cus

1.  If you count every year as 360 days, then you can try:

```declare @date date= '2017-05-30'
/*
----------
2015-06-10
*/```

or

```declare @date date= '2017-05-30'
/*
----------
2015-05-30
*/
```

(2) if you count two years actual days, then it should be 365+ 366 = 731 days. You can try this one :

```declare @date date= '2017-05-30'
DECLARE @year1 AS INT= datepart(yy,@date)
select dateadd(day,-[TOTAL NO OF DAYS],@date) from (
--/count the total days of two years
Select DATEPART(dy,DATEFROMPARTS(@Year1-2,12,31))+DATEPART(dy,DATEFROMPARTS(@Year1-1,12,31))
AS [TOTAL NO OF DAYS])a
/*
----------
2015-05-30
*/
```

Sabrina

MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

Tuesday, September 10, 2019 4:42 AM
• Hi

The below couple of approaches also work as you expected.

```--Approach-1

--Approach-2
```

Thank you

Tuesday, September 10, 2019 4:44 AM
• As per your problem statement, below is the simplest solution

Explanation: We are first adding -2 years from the current date, which gives date as '2015-05-30' (DATEADD(year,-2,'2017-05-30')) and then we can add 2 days which will give output as '2015-06-01'

However if we want to check the exact date 2 years back I think we should follow the below solution:

Explanation: We have 2 years to subtract (1 leap year and 1 non-leap Year). For leap years we need to consider 366 days and for non-leap years 365 days will be counted. So total days we need to subtract 731 days in order reach to the desired date: '2015-05-30'

• Proposed as answer by Tuesday, September 10, 2019 5:59 AM
Tuesday, September 10, 2019 5:53 AM
• Hi

I am writing to follow up this thread with you. Have you solved your issue? If you have solved your issue, please  mark helpful replies as answers. By doing so, it will benefit all community members who are having this similar issue.

Thank you