Skip to content

Instantly share code, notes, and snippets.

@patsissons
Forked from anonymous/ToSqlDateTimePrecision
Created May 20, 2014 04:52
Show Gist options
  • Save patsissons/29c57f4724b44bff6e46 to your computer and use it in GitHub Desktop.
Save patsissons/29c57f4724b44bff6e46 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