Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Is there a simple way to check if dates are 1 year diffe
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Versions des environnements
SQL Server:
SQL Server 2005
Divers
Thread ID:
01336573
Message ID:
01336581
Vues:
8
>>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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform