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)