public static void ConvertTimeSpanToSql_SqlServer(this StringBuilder stringBuilder, SqlDataType sqlDataType, TimeSpan value) { if (sqlDataType.Type.DataType == DataType.Int64) { stringBuilder.Append(value.Ticks); } else { var format = value.Days > 0 ? DateTimeConstants.TimeSpanFormat(value.Ticks % 10000000 != 0 ? 7 : 0) : DateTimeConstants.SqlTimeFormat(value.Ticks % 10000000 != 0 ? 7 : 0); stringBuilder.AppendFormat(CultureInfo.InvariantCulture, format, value); } }
public static string ToSqlTime(this TimeSpan ts, int milliSecondsPrecision = 0) => ts.ToString(DateTimeConstants.SqlTimeFormat(milliSecondsPrecision));