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 |
|
dannyboy86
Starting Member
8 Posts |
Posted - 2007-09-17 : 08:52:16
|
| I have a stored date in my database, example 12 October 2000 which is a start date - now i would like to retrieve this data and the number of years and months from the current date (that is today - i am using the getdate() method)...how can i get the number of years and months passed? Thanks |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-09-17 : 08:55:43
|
use datediff() to calculate the different in terms of month and divide by 12 to get the quotient (year) and remainder (month) KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-09-17 : 08:57:48
|
| 1 Always use proper DATETIME datatype to store dates (Which will solve,almost, all problem that you would have with handling dates)2 Let front end format the dates3 Select datediff(month,cast(varchar_col as datetime),getdate()) from tableMadhivananFailing to plan is Planning to fail |
 |
|
|
dannyboy86
Starting Member
8 Posts |
Posted - 2007-09-17 : 09:24:22
|
quote: Originally posted by khtan use datediff() to calculate the different in terms of month and divide by 12 to get the quotient (year) and remainder (month) KH[spoiler]Time is always against us[/spoiler]
thanks a lot, just what i needed |
 |
|
|
|
|
|