How can I convert the nullable DateTime dt2 to a formatted string?
DateTime dt = DateTime.Now;
Console.WriteLine(dt.ToString(\"yyyy-MM-dd hh
Seeing that you actually want to provide the format I'd suggest to add the IFormattable interface to Smalls extension method like so, that way you don't have the nasty string format concatenation.
public static string ToString(this T? variable, string format, string nullValue = null)
where T: struct, IFormattable
{
return (variable.HasValue)
? variable.Value.ToString(format, null)
: nullValue; //variable was null so return this value instead
}