码迷,mamicode.com
首页 > 数据库 > 详细

MSSQL 日期操作函数 总结

时间:2014-10-06 23:57:10      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   ar   sp   div   art   c   

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 日期操作函数 总结

标签:style   blog   color   io   ar   sp   div   art   c   

原文地址:http://www.cnblogs.com/niaowo/p/4008687.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!