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 |
scottichrosaviakosmos
Yak Posting Veteran
66 Posts |
Posted - 2010-06-29 : 09:34:26
|
i want to get date difference like a start date and end date and find difference in years but i want like if for example one date is 2007 and end date is 1 jan 2010 then the difference is of 3 years and one day so sql is showing 3 year .. but i want it to show 4 years. i.e even one day is extra should add that also.scoo |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2010-06-29 : 11:13:03
|
[code]declare @date1 datetime, @date2 datetimeselect @date1 = '2007-01-01', @date2 = '2010-01-02'select datediff(year, @date1, @date2) + case when @date2 > dateadd(year, year(@date2) - year(@date1), @date1) then 1 else 0 end[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|