Thursday, May 10, 2012

HOUR MINITE CALCULATION(find a difference between two different DATE)

HOUR MINITE CALCULATION(find a difference between two different DATE)

 

select

CAST(case when left(Minutes_Difference,1)='-' then Hours_Difference-1 else Hours_Difference end as varchar(10) )+':'+

cast(case when left(Minutes_Difference,1)='-' then 60+Minutes_Difference else Minutes_Difference end as varchar(10)) [Duration] from

(

 select DATEDIFF(HOUR,'2012-05-01 10:06:11.163','2012-05-03 13:03:15.840') as                                  Hours_Difference

,DATEDIFF(mi,DATEADD(hh,DATEDIFF(hh,'2012-05-01 10:06:11.163', '2012-05-03 13:03:15.840'),'2012-05-01 10:06:11.163'),'2012-05-03 13:03:15.840') as    Minutes_Difference

) t

No comments:

Post a Comment