• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 311
  • Last Modified:

DATEDIFF -- dd vs yy

is
DATEDIFF(yy, COLUMN1, COLUMN2 ) <=1
exactly same as
DATEDIFF(dd, COLUMN1, COLUMN2 ) <=365)

DATEDIFF(yy, COLUMN1, COLUMN2 ) BETWEEN 1 and 2
exactly same as
DATEDIFF(dd, COLUMN1, COLUMN2 ) BETWEEN 366 and 730
0
25112
Asked:
25112
  • 3
  • 2
4 Solutions
 
Rajkumar GsSoftware EngineerCommented:
No.

2011.01.01 &
2012.12.12
will have different results
0
 
25112Author Commented:
so
SELECT DATEDIFF(yy, '2011/01/01', '2012/12/12' )
does not look days but only the year part?
0
 
Rajkumar GsSoftware EngineerCommented:
Similarly for your second query,
2011.01.01 &
2013.12.12
won't work
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
Rajkumar GsSoftware EngineerCommented:
yes. Since
Yy - looks only year part
dd - only looks day part.
0
 
TempDBACommented:
This is because of the feature of the function. It first extract the datepart that is provided as a first argument, from second and third argument, and then subtracts. If its year, than only year part will be taken from full datetime, if month then only month. Similarly it happens for day, hour,second. You can only get an integer value of the datepart you are looking for basically.
It is very nicely shown by the example chosen by RajkumarGS.
0
 
25112Author Commented:
helped - thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now