Something like this should work:
let groupDate = DbFunctions.AddMonths(new DateTime(1753, 1, 1), EntityFunctions.DiffMonths(new DateTime(1753, 1, 1), p.BillDate))
(Using the namespace System.Data.Entity
)
Or:
let groupDate = SqlFunctions.DateAdd("month", SqlFunctions.DateDiff("month", new DateTime(1753, 1, 1), p.BillDate), new DateTime(1753, 1, 1))
(Using the namespace System.Data.Entity.SqlServer
)
The main difference between the two is that
SqlFunctions
only works for SQL Server, whereas
EntityFunctions
should work for other providers as well.
NB: 1st January 1753 is the earliest date supported by SQL's
datetime
type. If you're using SQL 2008 or later, your columns should be defined as
datetime2
, in which case you could use
DateTime.MinValue
instead.