Sunday, February 19, 2012

DATEDIFF() function in SQL server

i know this is specifically more an SQL server question than an ADO.NET question, but if anybody can clear this up for me that'd be great.

if i have a filter like the following:

WHERE DATEDIFF(day, H.HitDate, getdate()) = 1

is this going to work over the new year? what i mean is, if i run the query on january 1st, will it get all the rows from december 31st the previous year (and day)?

any help is greatly appreciatedYes, it will.

Prove it to yourself by running this code:


DECLARE @.myThisYearDate datetime
DECLARE @.myNextYearDate datetime

SET @.myThisYearDate = '12/31/2003'
SET @.myNextYearDate = '01/01/2004'

PRINT DATEDIFF(day,@.myThisYearDate,@.myNextYearDate)


Terri|||k, that seems to be working great.

thanks

No comments:

Post a Comment