Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Is there a simple way to check if dates are 1 year diffe
Message
General information
Forum:
Microsoft SQL Server
Category:
Other
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01336573
Message ID:
01336581
Views:
9
>>Hi everybody,
>>
>>If there a way to check for two date variables to be exactly one year apart or not?
>>
>>Thanks in advance.
>
>DECLARE @Test1 datetime
>DECLARE @Test2 datetime
>
>SET @Test1 = '20080101'
>SET @Test2 = '20090101'
>
>SELECT CASE WHEN DATEADD(mm,12,@Test1) = @Test2
>            THEN 'Hurray'
>            ELSE ':-(((((' END AS TestMe
>
I solved it as
select case when ABS(datediff(dd,dateadd(yyyy,1,'08/19/2008'),'08/28/2009')) < 2 then 1 else 0 end as OneYearApart from People in the meantime. Let me test yours.
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform