Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
CustomDateFormat.cs #blog
using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
public partial class UserDefinedFunctions
public static SqlString dateFormat(DateTime value, String formatString)
return new SqlString(value.ToString(formatString));
private struct ReturnValues
public SqlString Value;
private static void FillValues(object obj, out SqlString TheValue)
ReturnValues ReturnVals = (ReturnValues)obj;
TheValue = ReturnVals.Value;
[Microsoft.SqlServer.Server.SqlFunction(DataAccess = DataAccessKind.None,
IsDeterministic = true,
IsPrecise = true,
SystemDataAccess = SystemDataAccessKind.None,
FillRowMethodName = "FillValues",
TableDefinition = "formattedDate nvarchar(50)")]
public static System.Collections.IEnumerable TVF_Streaming(DateTime value, String formatString)
ReturnValues Vals = new ReturnValues();
Vals.Value = new SqlString(value.ToString(formatString));
yield return Vals;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment