CARA MUDAH HITUNG DURASI WAKTU DI SQL SERVER
declare @time_a datetime
,@time_b datetime
,@jlh_hari int
,@jlh_jam int
,@jlh_menit int
,@jlh_detik int
set @time_a = '2011-07-19 11:45:11'
set @time_b = '2011-08-20 12:44:10'
-- hitung jumlah waktu dari waktu A ke waktu B
set @jlh_hari = datediff(hour, @time_a, @time_b)/24
set @jlh_jam = datediff(minute, @time_a, @time_b)/60%24
set @jlh_menit = datediff(second, @time_a, @time_b)/60%60
set @jlh_detik = datediff(second, @time_a, @time_b)%60
select @jlh_hari
,@jlh_jam
,@jlh_menit
,@jlh_detik
--hasil = 32 hari, 0 jam, 58 menit, 59 detik
--arthur
,@time_b datetime
,@jlh_hari int
,@jlh_jam int
,@jlh_menit int
,@jlh_detik int
set @time_a = '2011-07-19 11:45:11'
set @time_b = '2011-08-20 12:44:10'
-- hitung jumlah waktu dari waktu A ke waktu B
set @jlh_hari = datediff(hour, @time_a, @time_b)/24
set @jlh_jam = datediff(minute, @time_a, @time_b)/60%24
set @jlh_menit = datediff(second, @time_a, @time_b)/60%60
set @jlh_detik = datediff(second, @time_a, @time_b)%60
select @jlh_hari
,@jlh_jam
,@jlh_menit
,@jlh_detik
--hasil = 32 hari, 0 jam, 58 menit, 59 detik
--arthur
Label: hitung waktu sql server