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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Stored Procedure - Date Problems

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]

Go to Top of Page

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 dates
3 Select datediff(month,cast(varchar_col as datetime),getdate()) from table

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

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
Go to Top of Page
   

- Advertisement -