Skip to content

Instantly share code, notes, and snippets.

Created March 26, 2014 21:27
Show Gist options
  • Save anonymous/9793987 to your computer and use it in GitHub Desktop.
Save anonymous/9793987 to your computer and use it in GitHub Desktop.
// handy extension method to reduce a DateTime to the precision of a T-SQL DATETIME so that you can compare it with
// CLR DateTime's in unit tests
public static partial class ExtensionMethods
{
public static DateTime ToSqlDateTimePrecision(this DateTime source)
{
using (var ctx = new Data.DataContext())
{
return ctx.ExecuteQuery<DateTime>(string.Format("SELECT CONVERT(DATETIME, '{0}', 0)", source)).Single();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment