Format a date : Utility function « Procedure Function « SQL Server / T-SQL Tutorial






3> CREATE FUNCTION MyDateFormat
4>          (@indate datetime,
5>           @Separator char(1)='-')
6> RETURNS nchar(20)
7> AS
8> BEGIN
9>     RETURN
10>         CONVERT(nvarchar(20), DATEPART(dd, @indate))
11>         + @Separator
12>         + CONVERT(nvarchar(20), DATEPART(mm, @indate))
13>         + @Separator
14>         + CONVERT(nvarchar(20), DATEPART(yy, @indate))
15> END
16> GO
1>
2> SELECT dbo.MyDateFormat(GETDATE(), '*')
3> GO

--------------------
17*8*2008
1>
2>
3> drop FUNCTION MyDateFormat;
4> GO








21.6.Utility function
21.6.1.Scalar Functions
21.6.2.Format a date
21.6.3.linear_max() Scalar Function
21.6.4.The linear_min Scalar Function
21.6.5.Changing Character Values to Proper Case with user-defined functions
21.6.6.if an int odd