getting date difference in sql server
Hello everyone
My problem is as folow
i have one table where there are two columns name prealert date and GRN Date
TransactionID
Prealert Date
GRN Date
1
2011-08-12 00:00:00.000
2011-08-03 00:00:00.000
I want difference of these two columns in number of days into new column name differnce
TransactionID
Prealert Date
GRN Date
Difference in Days
1
2011-08-12 00:00:00.000
2011-08-03 00:00:00.000
9
can anyone can please tell me SQL query for this particular problem
regards
ajay singh rawat
August 24th, 2011 6:53am
You can use this
select [TransactionID],[Prealert Date],[GRN Date],DateDiff(d,[GRN Date],[Prealert Date]) as [Difference in Day]
--------------------------------------------------------
Surender Singh Bhadauria
Free Windows Admin Tool Kit Click here and download it now
August 24th, 2011 7:04am
check this code locally...
and try to change the column names...
CREATE TABLE dbo.Duration
(
startDate datetime2
,endDate datetime2
)
INSERT INTO dbo.Duration(startDate,endDate)
VALUES('2007-05-05 12:10:09','2007-05-07 12:10:09')
SELECT DATEDIFF(day,startDate,endDate) AS 'Days'
FROM dbo.Duration;
Let us TRY this | Mail me
My Blog :: http://quest4gen.blogspot.com/
August 24th, 2011 7:45am