September 19, 2006 at 1:39 am
hi
thanxs it works the out put is 14 Years 8 Months 261 days .
but i need for all the data in the column eg :i will pass the column name i should get all the result here iam passing the value ('01/05/1992',GETDATE()) i will pass ('birthdate',GETDATE())how do i find date month year diff
thanxs
September 19, 2006 at 2:06 am
Hi,
Use following syntax:
To get day : select datepart(day,getdate())
To get month : select datepart(month,getdate())
To get year : select datepart(year,getdate())
Thanks
Bingi
September 19, 2006 at 5:59 am
Do you want to calculate difference between two days in terms of Years, Months and Days like difference between current date and '01/01/2000' or something of that sort?
Prasad Bhogadi
www.inforaise.com
September 19, 2006 at 6:37 am
DECLARE @months int
SET @months = DATEDIFF(month,@firstdate,@seconddate)
SELECT @months % 12 AS [Months],@months / 12 AS [Years]
Some more detail and example data and results would be helpful
Far away is close at hand in the images of elsewhere.
Anon.
September 19, 2006 at 7:43 am
You can wrap the code posted by David and create UDF and call it in your queries.
CREATE FUNCTION dbo.CalDateDiff(@firstdate DATETIME, @seconddate DATETIME)
RETURNS VARCHAR(100)
AS
BEGIN
DECLARE @months int
DECLARE @days INT
DECLARE @DateDifference VARCHAR(50)
SET @months = DATEDIFF(month,@firstdate,@seconddate)
SET @days = DATEDIFF(day,@firstdate,@seconddate)
SET @DateDifference = (SELECT CAST(@months / 12 AS VARCHAR)+ ' Years ' + CAST(@months % 12 AS VARCHAR)+ ' Months ' + CAST(@days % 365 -1 AS VARCHAR) + ' days')
RETURN @DateDifference
END
SELECT dbo.CalDateDiff ('01/01/2006',GETDATE()) AS DateDifference
Thx
Prasad Bhogadi
www.inforaise.com
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply