MSSQL 日期操作函数 总结

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER FUNCTION [dbo].[ufn_getDateOfWeek]
(@Date Datetime)
RETURNS nchar(1)
AS
BEGIN
 DECLARE @returnValue nchar(1);
 
    SET @returnvalue = case datepart(dw,@Date) when 2 then  
                                               when 3 then 
                                               when 4 then 
                                               when 5 then 
                                               when 6 then 
                                               when 7 then 
                                               when 1 then 
                       end;
 RETURN @returnValue
END
 
 
 
---------------------
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
 
 
ALTER FUNCTION [dbo].[ufn_TransDate]
(
 @Date DATETIME
)
RETURNS nvarchar(50)
AS
/*    
Action:  讲时间传换成这样的格式 01-18 14:00
CreatedBy: 
CreatedDate: 2011-01-19 11:44:12.920
ModifiedHistory:
Test Scripts:
print dbo.ufn_TransDate(‘2011-01-19 11:44:12.920‘)
*/ 
BEGIN
 DECLARE @Str NVARCHAR(50)
 
 SET @Str = Convert(Nvarchar(19),Convert(DateTime,@Date,120),120)
 
 SET @Str = SUBSTRING(@Str,6,11)
 
 RETURN @Str
END
 
 
 
 
---------------------------------------
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
 
 

ALTER FUNCTION [dbo].[ufn_TransDate2]
(
 @Date DATETIME
)
RETURNS nvarchar(50)
AS
/*    
Action:  讲时间传换成这样的格式 2011-01-18
CreatedBy:
CreatedDate: 2011-01-19 11:44:12.920
ModifiedHistory:
Test Scripts:
print dbo.ufn_TransDate2(‘2011-01-19 11:44:12.920‘)
*/ 
BEGIN
 DECLARE @Str NVARCHAR(50)
 
 SET @Str = Convert(Nvarchar(19),Convert(DateTime,@Date,120),120)
 
 SET @Str = SUBSTRING(@Str,1,11)
 
 RETURN @Str
END
 
 
 

 
----------------------------------------------

 

MSSQL 日期操作函数 总结

上一篇:SQL语句统计每天、每月、每年的 数据


下一篇:翻译:使用 ASP.NET MVC 4, EF, Knockoutjs and Bootstrap 设计和开发站点 - 5 - 数据库设计