【发布时间】:2012-02-28 22:52:23
【问题描述】:
我下面有以下功能。
它返回一个日期,例如 2012 年 2 月 29 日晚上 10:00。有没有办法让它返回格式为 2/29/2012 10:00PM
CREATE FUNCTION scrubDateString
(
-- Add the parameters for the function here
@inputDate varchar(150)
)
RETURNS DATETIME
AS
BEGIN
-- Declare the return variable here
DECLARE @Result DATETIME
-- Add the T-SQL statements to compute the return value here
DECLARE @tmpDate datetime
SET @Result = null
IF (ISDATE(@inputDate)=1)
BEGIN
SET @Result = DATEADD(HH, 5, @inputDate)
END
-- Return the result of the function
RETURN @Result
END
【问题讨论】:
-
我如何考虑UTC时间,例如这个函数将负责更新数据库中的表。根据安装程序的执行位置,我需要此函数返回 UTC 时间。
标签: sql sql-server tsql