sql server 2005 将时间转换为分钟 [英] sql server 2005 convert time to minutes
本文介绍了sql server 2005 将时间转换为分钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的数据库中有几个日期时间函数,但我需要添加一个获取日期时间字段的时间部分然后将时间转换为分钟的函数
I have a few date time functions within my database, but I need to add one that takes the time portion of a datetime field and then converts the time into minutes
我有一个函数可以获取两次之间的分钟数,但不仅仅是一次的分钟数.
I have a function that get the minutes between two times, but not just the minutes of a single time.
ALTER FUNCTION [dbo].[fn_MinutesBetween]
( @fStart datetime, @fEnd datetime )
RETURNS int
AS
BEGIN
RETURN DateDiff(minute, @fStart, @fEnd)
另一个只得到时间部分
ALTER function [dbo].[fn_ReturnTimeOnly]
(@DateTime smallDateTime)
returns nvarchar(50)
as
begin
Return substring(cast(@DateTime as varchar),12,len(@DateTime))
end
我怎样才能得到时间的分钟.比如凌晨 1:00 是 60,凌晨 2:00 是 12012:00 pm 是 720 等
How can I just get the minutes of the time. Like 1:00 am would be 60, 2:00 am would be 120 12:00 pm would be 720 etc.
谢谢
推荐答案
我在评论中得到了一个链接到 日期时间到总分钟数并以此想出一个解决方案.
I was given a link in comments to datetime to totalminute and used that to come up with a solution.
ALTER FUNCTION [dbo].[fn_ReturnMinutesOnly]
( @dt smalldatetime )
RETURNS int
AS
BEGIN
RETURN DATEDIFF(MINUTE, DATEADD(DAY, DATEDIFF(DAY, 0, @dt), 0), @dt)
END
这篇关于sql server 2005 将时间转换为分钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文