SetAnsi_nulls onSetQuoted_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 'a' when 3 Then 'two' when 4 Then 'three' when 5 Then 'Four' when 6 Then 'Five' when 7 Then 'Six' when 1 Then 'Day' End; RETURN @returnValueEND ---------------------SetAnsi_nulls onSetQuoted_identifier onGo ALTER FUNCTION [dbo].[ufn_transdate]( @Date DATETIME)RETURNS nvarchar( -) as/*Action: Tell time to change to this format 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( -) SET @Str = Convert(Nvarchar( +),Convert(DateTime,@Date, -), -) SET @Str = SUBSTRING(@Str,6, One) RETURN @StrEND ---------------------------------------SetAnsi_nulls onSetQuoted_identifier onGo ALTER FUNCTION [dbo].[Ufn_transdate2]( @Date DATETIME)RETURNS nvarchar( -) as/*Action: Tell time to change to this format 2011-01-18createdby:createddate:2011-01-19 11:44:12.920modifiedhistory:test scripts:print D Bo.ufn_transdate2 (' 2011-01-19 11:44:12.920 ')*/ BEGIN DECLARE @Str NVARCHAR( -) SET @Str = Convert(Nvarchar( +),Convert(DateTime,@Date, -), -) SET @Str = SUBSTRING(@Str,1, One) RETURN @StrEND ----------------------------------------------
MSSQL Date Operation Function Summary