I hate to say it but the function is working as designed. I ran into the
same issue when looking for the number of months between dates.
From SQL Server's Books Online: The method of counting crossed boundaries
such as minutes, seconds, and milliseconds makes the result given by
DATEDIFF
to summarize, the following transact-sql code is touted by The
Guru's Guide to Transact-SQL as the best solution to return only
those employees whose hire date anniversaries fall within the
next 30 days:
select fname, lname, hire_date from employees
where datediff (yy, hire_date, getdate()) +
Just a guess, but in the datediff you are just extracting the year. If you
want to include the
month in the calculation, you should probably get the month part too.
Margaret
-Original Message-
From: Dina Hess [mailto:[EMAIL PROTECTED]]
Sent: Monday, May 06, 2002 11:20 AM
To: CF-Talk
Subject: RE: transact-sql datediff function
Just a guess, but in the datediff you are just extracting the
year. If you
want to include the
month in the calculation, you should probably get the month
part too.
Margaret
-Original Message-
From: Dina Hess [mailto:[EMAIL PROTECTED
, May 06, 2002 4:17 PM
To: CF-Talk
Subject: Re: transact-sql datediff function
thanks for taking a look at it, margaret. but the whole idea is
that i'm trying to find the difference (in years) between the
hire date and today's date.
~ dina
- Original Message -
From: Margaret Fisk [EMAIL
) datediff (yy,
hire_date, getdate())
maybe i'm doing something stupid. does this code work for you?
~ dina
- Original Message -
From: Ryan Pieszak [EMAIL PROTECTED]
To: CF-Talk [EMAIL PROTECTED]
Sent: Monday, May 06, 2002 3:31 PM
Subject: RE: transact-sql datediff function
I think
Message-
From: Dina Hess [mailto:[EMAIL PROTECTED]]
Sent: Monday, May 06, 2002 1:17 PM
To: CF-Talk
Subject: Re: transact-sql datediff function
thanks for taking a look at it, margaret. but the whole idea is that i'm
trying to find the difference (in years) between the hire date and today's
), it works. Let me know if it works for you.
I'm leaving for the day, I'll check my mail in the morning.
Ryan
-Original Message-
From: Dina Hess [mailto:[EMAIL PROTECTED]]
Sent: Monday, May 06, 2002 5:16 PM
To: CF-Talk
Subject: Re: transact-sql datediff function
well, here...
i'm a newbie
8 matches
Mail list logo