首页 > 代码库 > MSSQL 日期操作函数 总结

MSSQL 日期操作函数 总结

set ANSI_NULLS ONset QUOTED_IDENTIFIER ONgoALTER FUNCTION [dbo].[ufn_getDateOfWeek](@Date Datetime)RETURNS nchar(1)ASBEGIN 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 @returnValueEND   ---------------------set ANSI_NULLS ONset QUOTED_IDENTIFIER ONgo  ALTER FUNCTION [dbo].[ufn_TransDate]( @Date DATETIME)RETURNS nvarchar(50)AS/*    Action:  讲时间传换成这样的格式 01-18 14:00CreatedBy: CreatedDate: 2011-01-19 11:44:12.920ModifiedHistory: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 @StrEND    ---------------------------------------set ANSI_NULLS ONset QUOTED_IDENTIFIER ONgo  ALTER FUNCTION [dbo].[ufn_TransDate2]( @Date DATETIME)RETURNS nvarchar(50)AS/*    Action:  讲时间传换成这样的格式 2011-01-18CreatedBy:CreatedDate: 2011-01-19 11:44:12.920ModifiedHistory: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 @StrEND    ----------------------------------------------

 

MSSQL 日期操作函数 总结