sql 秒转时分秒 考勤用到,来源网上
代码
create function fun_SecondsToHourMinuteSecond(@seconds bigint)
returns varchar(20)
as
begin
declare @str as varchar(20)
if @seconds > 10 --如果秒数大于10
begin
declare @hour as varchar(10)
declare @minute as varchar(10)
declare @second as varchar(10)
if(@seconds/3600 < 10)
begin
set @hour = '0' + convert(varchar(10),@seconds/3600)
end
else
begin
set @hour = convert(varchar(10),@seconds/3600)
end
if(@seconds%3600/60 < 10)
begin
set @minute = '0' + convert(varchar(10),@seconds%3600/60)
end
else
begin
set @minute = convert(varchar(10),@seconds%3600/60)
end
if(@seconds%3600%60 < 10)
begin
set @second = '0' + convert(varchar(10),@seconds%3600%60%60)
end
else
begin
set @second = convert(varchar(10),@seconds%3600%60%60)
end
set @str = @hour + ':' + @minute + ':' + @second
end
else --如果秒数小于10
begin
set @str = '00:00:0'+convert(varchar(20),@seconds)
end
return(@str)
end
returns varchar(20)
as
begin
declare @str as varchar(20)
if @seconds > 10 --如果秒数大于10
begin
declare @hour as varchar(10)
declare @minute as varchar(10)
declare @second as varchar(10)
if(@seconds/3600 < 10)
begin
set @hour = '0' + convert(varchar(10),@seconds/3600)
end
else
begin
set @hour = convert(varchar(10),@seconds/3600)
end
if(@seconds%3600/60 < 10)
begin
set @minute = '0' + convert(varchar(10),@seconds%3600/60)
end
else
begin
set @minute = convert(varchar(10),@seconds%3600/60)
end
if(@seconds%3600%60 < 10)
begin
set @second = '0' + convert(varchar(10),@seconds%3600%60%60)
end
else
begin
set @second = convert(varchar(10),@seconds%3600%60%60)
end
set @str = @hour + ':' + @minute + ':' + @second
end
else --如果秒数小于10
begin
set @str = '00:00:0'+convert(varchar(20),@seconds)
end
return(@str)
end
______________________________________
生活,要用圣人的胸怀面对,用科学的方法支配,
用皇帝的御膳养胃,用清洁的空气洗肺,
用小猪的感觉去睡,用太阳的热情灌水。
______________________________________