sql server - Adding date difference of two dates in Sql for all columns -
i have table 2 date columns arrivaldate , departuredate. need calculate total time period in hours , minutes (not date) of entries in table . can time period of particular record via datediff need sum of date differences in table in hours , minutes .
what doing getting date difference
set @startdate = '10/01/2012 08:40:18.000' set @enddate = '10/04/2012 09:52:48.000' select convert(char(8), cast(convert(varchar(23),@enddate,121) datetime) -cast(convert(varchar(23),@startdate,121)as datetime),8) timediff this gives particular date difference . need date differences in table , there sum.
this query generate results looking for:
select sum(datediff(minute, r.arrivaldate, r.departuredate)) / 60 totalhours , sum(datediff(minute, r.arrivaldate, r.departuredate)) % 60 totalminutes tablewithdates r the first column returned divides total minutes 60 give whole number of hours. second column returned calculates remainder when dividing total minutes 60 give additional minutes remaining. combined 2 columns give sum total of elapsed hours , minutes between of arrival , departure dates.
Comments
Post a Comment