| Author |
Topic |
|
js.reddy
Yak Posting Veteran
80 Posts |
Posted - 2011-08-12 : 02:06:06
|
| HiI want to write a function which should return Years Months days.i.e '10 : 6 : 20'My input will be StartDate and EndDate. So i want to display the difference in the above format.Thanksjs.reddy |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-08-12 : 02:09:50
|
use datediff(day, startdate, enddate) to find the different in terms of days and the convert to month, year accordingly KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-08-12 : 02:13:04
|
this will give you approx difference in yr month daysSELECT DATEDIFF(dd,@Start,@End)/365 as Yr,(DATEDIFF(dd,@Start,@End)%365)/30 AS Mnth, ((DATEDIFF(dd,@Start,@End)%365)%30) AS Days ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
js.reddy
Yak Posting Veteran
80 Posts |
Posted - 2011-08-12 : 02:15:28
|
How you can convert days into years and months ?all months & years are not same days right ?leap year is 366 days. feb is 28 days.so how it is possible!!quote: Originally posted by khtan use datediff(day, startdate, enddate) to find the different in terms of days and the convert to month, year accordingly KH[spoiler]Time is always against us[/spoiler]
|
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-08-12 : 02:17:37
|
quote: Originally posted by js.reddy How you can convert days into years and months ?all months & years are not same days right ?leap year is 366 days. feb is 28 days.so how it is possible!!quote: Originally posted by khtan use datediff(day, startdate, enddate) to find the different in terms of days and the convert to month, year accordingly KH[spoiler]Time is always against us[/spoiler]
exactly. You have to tell us how do you want to calculate. If not use visakh16 method KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
js.reddy
Yak Posting Veteran
80 Posts |
Posted - 2011-08-12 : 02:29:13
|
Visakh, Still it will not give exact result.quote: Originally posted by visakh16 this will give you approx difference in yr month daysSELECT DATEDIFF(dd,@Start,@End)/365 as Yr,(DATEDIFF(dd,@Start,@End)%365)/30 AS Mnth, ((DATEDIFF(dd,@Start,@End)%365)%30) AS Days ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
|
 |
|
|
js.reddy
Yak Posting Veteran
80 Posts |
Posted - 2011-08-12 : 02:36:19
|
guys, here what i mean is, i want know the exact age of a person based on his date of birth.the output should be as below:12 years 10 Months 15 days or 12:10:15this is what my requirement. please help me any one in this regard.Thanksquote: Originally posted by js.reddy HiI want to write a function which should return Years Months days.i.e '10 : 6 : 20'My input will be StartDate and EndDate. So i want to display the difference in the above format.Thanksjs.reddy
|
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
|
|
|