Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
madlo
Starting Member
41 Posts |
Posted - 2011-08-02 : 15:05:14
|
| I have a query to get all the dates that are greater than five yearie. When I user 2011/08/01 as criteria it should include 2016/08/02 but exclude 2016/08/01 However datediff(year,startdate,enddate) will always give 10 as it just looks at the year part. Is there an easy way to get the relative year. |
|
|
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2011-08-02 : 15:13:38
|
Declare @dt datetimeSet @dt = '2011/08/01'Select * From yourTable Where startDate > dateadd(year, 5, @dt)Corey I Has Returned!! |
 |
|
|
himabindu.nvn
Starting Member
1 Post |
Posted - 2011-08-02 : 19:02:50
|
| select * from table where yearcolumn>dateadd(yy,-5,getdate())I am new to sql programming. Please let me know if my understanding is right! |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-08-03 : 01:07:50
|
quote: Originally posted by himabindu.nvn select * from table where yearcolumn>dateadd(yy,-5,getdate())I am new to sql programming. Please let me know if my understanding is right!
it should be +5 not -5 as you want 5 years ahead------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
madlo
Starting Member
41 Posts |
Posted - 2011-08-04 : 07:30:06
|
| This issue is the same as determining the age from the date of birth so I will just use the method described in those threads. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
|
|
|