Possible Duplicate:
Difference in months
Hi all:
how can We calculate the months difference between two dates using LINQ ? I can find days difference using:
(p.Account.StateChangeDate.Date - DateTime.Now.Date).Days < 4
but there is no option for months.
Please suggest.
Try calculating the difference in months between two dates
Pick the algorithm you want to use from that question.
Then, if you are using Linq2Sql, then almost all of those will get mapped back to the database as DATEPART type operations (I think).
Alternatively you could do the calc in SQL using a function like in http://www.sqlmag.com/article/sql-server/calculating-month-difference.aspx - and could then expose that to Linq2Sql as a function
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With